{
$data[rand(1,100)] = rand(1,100);
}
//sort using custom compare
uksort($data, "compare");
//show sorted array
foreach($data as $key=>$value)
{
print($key. "=". $value. "
\n");
}
?>
usort(array unsorted_array, string compare_function)
The usort function sorts an array by element values using a custom comparison function.
The function must return a signed integer. If it returns zero, then two elements are
considered equal. If a negative number is returned, the two elements are considered to be
in order. If a positive number is returned, the two elements are considered to be out of
order.
<?
/*
* duplicate normal ordering
/
function compare($left, $right)
{
return($left - $right);
}
//create test data
srand(time());
for($i=0; $i<10; $i++)
{
$data[rand(1,100)] = rand(1,100);
}
//sort using custom compare
usort($data, "compare");
//show sorted array
foreach($data as $key=>$value)
{
print($key. "=". $value. "
\n");
}
?>
Hashing