CKTIS / PHP
max()
With one nonempty array, max selects its greatest value rather than its key.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
max(mixed $value, mixed ...$values): mixedWith one nonempty array, max selects its greatest value rather than its key. With two or more arguments it compares those arguments according to PHP comparison rules. The selected original value retains its type, and equivalent candidates leave the first in place. An empty array supplied alone raises ValueError.
Signature
max(mixed $value, mixed ...$values): mixed
Example output
[9,"10","string",5]
ValueError
Examples
<?php
$first = max("10", 10);
echo json_encode([max(["a" => 3, "b" => 9]), $first, get_debug_type($first), max(2, 5, 4)]), PHP_EOL;
try { max([]); } catch (ValueError $e) { echo get_class($e); }
Result
[9,"10","string",5] ValueError