CKTIS / PHP
sort()
Ordina i valori in senso crescente nello stesso array e scarta le chiavi originali.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
sort(array &$array, int $flags = SORT_REGULAR): trueOrdina i valori in senso crescente nello stesso array e scarta le chiavi originali. SORT_NUMERIC confronta le quantità senza trasformare le stringhe numeriche memorizzate in int. Restituisce true.
Firma
sort(array &$array, int $flags = SORT_REGULAR): true
Output dell’esempio
[true,["0","2","10"]]
Esempi
<?php
$stock = ["large"=>"10","small"=>"2","none"=>"0"];
$ok = sort($stock,SORT_NUMERIC);
echo json_encode([$ok,$stock]);
Risultato
[true,["0","2","10"]]