Common standard-library functions
Standard functions handle common collection, JSON, date, and validation tasks.
What it is
Standard functions handle common collection, JSON, date, and validation tasks.
When to use it
Prefer established functions over handwritten parsing.
Syntax
count($items);
in_array($role, $allowed, true);
array_column($users, "id");
json_encode($data, JSON_THROW_ON_ERROR);Example
try {
$payload = json_encode(["ids" => array_column($users, "id")], JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
throw new RuntimeException("Cannot serialize response", previous: $e);
}Common mistakes
Use strict in_array; do not assume JSON encoding always succeeds.