Función PHP usort()
Ejemplo
Ordene los elementos de la matriz $a usando una función de comparación definida por el usuario:
<?php
function my_sort($a,$b)
{
if ($a==$b) return 0;
return ($a<$b)?-1:1;
}
$a=array(4,2,8,6);
usort($a,"my_sort");
?>
Definición y uso
La función usort() ordena una matriz usando una función de comparación definida por el usuario.
Sintaxis
usort(array, myfunction)
Valores paramétricos
Parameter | Description |
---|---|
array | Required. Specifies the array to sort |
myfunction | Optional. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument |
Detalles técnicos
Valor devuelto: | VERDADERO sobre el éxito. FALSO en falla |
---|---|
Versión PHP: | 4+ |
❮ Referencia de matriz de PHP