CKTIS / PHP
asort()
Ordina i valori in senso crescente mantenendo le chiavi.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
asort(array &$array, int $flags = SORT_REGULAR): trueOrdina i valori in senso crescente mantenendo le chiavi. SORT_STRING colloca il testo "10" prima di "2", mentre SORT_NUMERIC confronta le quantità. Modifica l’argomento e restituisce true. In PHP 8 i valori uguali mantengono l’ordine iniziale. Il puntatore interno si posiziona sul primo elemento ordinato.
Firma
asort(array &$array, int $flags = SORT_REGULAR): true
Output dell’esempio
[["ten","two"],["two","ten"]]
[["p","q","z"],"p"]
Esempi
<?php
$prices = ["ten"=>"10","two"=>"2"];
$lexical = $prices; asort($lexical,SORT_STRING);
asort($prices,SORT_NUMERIC);
echo json_encode([array_keys($lexical),array_keys($prices)]);
$ties=["z"=>3,"p"=>1,"q"=>1]; end($ties); asort($ties);
echo PHP_EOL,json_encode([array_keys($ties),key($ties)]);
Risultato
[["ten","two"],["two","ten"]] [["p","q","z"],"p"]