This is an old revision of the document!
WattmonOS 3.14+
Sort an array using the quick sort algorithm
/lib/uphp/array.inc
Sort an array by key, value or using a callback function
$array_to_sort: Array to be sorted
$method: One of the following methods:
^ Type ^ Value ^ Description ^
SORT_KEY | 0 | Sort an array by the key |
SORT_VALUE | 1 | Sort an array by the value |
SORT_FUNC | 2 | Sort an array using a callback function |
array containing the sorted values
Sort an array using a callback to look at the array elements. The array contains a sub-array for each element with the keys 'order' and 'name'.
<pre><? $unsorted = array(); for ($i=0;$i<10;$i++) { $arr=array(); $arr['order']=rand(0,100); $arr['name']='item'.$i; $unsorted[]=$arr; } function compare($a1,$a2) { if ($a1['order'] < $a2['order']) return 1; return 0; } $sorted = quick_sort($unsorted, SORT_FUNC,'compare'); print_r($sorted); // spew out the sorted array ?></pre>