Forum und email

uksort

(PHP 4, PHP 5)

uksort — Ordena una matriz por claves mediante una función definida por el usuario

Descripción

void uksort ( array &$matriz , function $func_comparar )

Esta función ordenará las claves de una matriz utilizando una función de comparación suministrada por el usuario. Si la matriz a ordenar necesita utilizar un criterio poco trivial, esta es la función que deberá usar.

Function cmp_function should accept two parameters which will be filled by pairs of array keys. The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

Devuelve TRUE si todo se llevó a cabo correctamente, FALSE en caso de fallo.

Example#1 Ejemplo de uksort()

<?php
function cmp($a$b
{
    if (
$a == $b) {
        return 
0;
    }
    return (
$a $b) ? -1;
}

$a = array(=> "four"=> "three"20 => "twenty"10 => "ten");

uksort($a"cmp");

while (list(
$key$value) = each($a)) {
    echo 
"$key: $value\n";
}
?>

El resultado del ejemplo seria:

20: twenty
10: ten
4: four
3: three

Vea también: usort(), uasort(), sort(), asort(), arsort(), ksort(), natsort(), y rsort().