usort

It sorts an array by keys using a user-defined comparison function

Example

<?php
function func($a, $b)
{
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
echo “<pre>”;
$array = array(1, 7, 5, 8, 4);
usort($array, “func”);
print_r($array);
?>

Output

Array
(
[0] => 1
[1] => 4
[2] => 5
[3] => 7
[4] => 8
)

Share