CKTIS / PHP
max()
Con un solo array non vuoto max seleziona il valore maggiore indipendentemente dalla chiave.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
max(mixed $value, mixed ...$values): mixedCon un solo array non vuoto max seleziona il valore maggiore indipendentemente dalla chiave. Con almeno due argomenti confronta gli argomenti secondo le regole PHP. Il tipo originale è conservato e in caso di parità vince il primo. Un solo array vuoto solleva ValueError.
Firma
max(mixed $value, mixed ...$values): mixed
Output dell’esempio
[9,"10","string",5]
ValueError
Esempi
<?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); }
Risultato
[9,"10","string",5] ValueError