CKTIS / PHP
uksort()
Passa le chiavi a un comparatore intero, ad esempio per ordinare le etichette per lunghezza.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
uksort(array &$array, callable $callback): truePassa le chiavi a un comparatore intero, ad esempio per ordinare le etichette per lunghezza. Conta solo il segno. Con zero PHP 8 mantiene l’ordine precedente e i valori restano associati.
Firma
uksort(array &$array, callable $callback): true
Output dell’esempio
{"x":4,"ab":9,"long":7}
Esempi
<?php
$tags = ["long"=>7,"x"=>4,"ab"=>9];
uksort($tags, fn($left,$right) => strlen($left) <=> strlen($right));
echo json_encode($tags);
Risultato
{"x":4,"ab":9,"long":7}