Oihana PHP System

getQueryParam.php

Table of Contents

Functions

getQueryParam()  : mixed
Retrieves a single parameter from the HTTP request query string.

Functions

getQueryParam()

Retrieves a single parameter from the HTTP request query string.

getQueryParam(ServerRequestInterface|null $request, string $name) : mixed

This helper extracts a value from the query parameters ($request->getQueryParams()), supporting dot notation for nested structures (e.g. 'filter.page').

It internally uses hasKeyValue() and getKeyValue() from the oihana\core\accessors namespace.

If the request is null, or if the specified parameter does not exist, the function returns null.

Parameters
$request : ServerRequestInterface|null

The PSR-7 server request instance. If null, no extraction is performed.

$name : string

The query parameter name or nested key path (e.g. 'filter.page').

Tags
example

Retrieve a flat parameter:

// URL: /api/users?name=Alice&age=30
echo getQueryParam($request, 'name'); // 'Alice'
echo getQueryParam($request, 'age');  // '30'

Retrieve a nested parameter using dot notation:

// URL: /api/users?filter[page]=2&filter[limit]=10
echo getQueryParam($request, 'filter.page');  // '2'
echo getQueryParam($request, 'filter.limit'); // '10'

Handle missing keys or null request:

getQueryParam(null, 'foo');            // null
getQueryParam($request, 'not.exists'); // null
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
mixed

The parameter value if found, or null otherwise.


        
On this page

Search results