getBodyParams.php
Table of Contents
Functions
- getBodyParams() : array<string|int, mixed>
- Retrieves multiple parameters from the HTTP request body.
Functions
getBodyParams()
Retrieves multiple parameters from the HTTP request body.
getBodyParams(ServerRequestInterface|null $request[, array<string|int, mixed> $names = [] ]) : array<string|int, mixed>
This helper extracts one or more values from the parsed request body ($request->getParsedBody()),
supporting dot notation for nested structures (e.g. 'user.address.city').
Each requested key from $names is resolved recursively via
hasKeyValue() and getKeyValue(), and reassembled into a new associative
array using setKeyValue(). The request body is first normalized into a pure associative
array using toAssociativeArray(), ensuring compatibility with both array and stdClass payloads.
If the request is null, the function returns null.
If none of the requested keys exist, an empty array is returned.
Parameters
- $request : ServerRequestInterface|null
-
The PSR-7 server request instance. If
null, no extraction is performed. - $names : array<string|int, mixed> = []
-
A list of parameter names (keys or dot-notated paths) to extract.
Tags
Return values
array<string|int, mixed> —An associative array of extracted values. Nested keys are preserved according to dot notation.