array handling
|array multi sort
| see demonstration of array multi sortsort multidimensional arrays by field specified.
specify the key by which you want your multiarray sorted.
full source of array multi sort [ line 1 - 23 ] | download array multi sort
| 1 | <?php |
| 2 | // demo array to sort |
| 3 | $latest_array = array( |
| 4 | array('news','1234567890','sdf','asdpojq'), |
| 5 | array('news','1234567892','uruy','xbuqiwpo'), |
| 6 | array('comment','1234567893','fghj','mjktyu'), |
| 7 | array('article','1234567891','cvmo','pjklgg'), |
| 8 | array('news','1234567894','qwenb','asbhtyhj'), |
| 9 | ); |
| 10 | $sort_field = 3; // enter the number of field to sort |
| 11 | // compare function |
| 12 | function cmpi($a, $b) |
| 13 | { |
| 14 | global $sort_field; |
| 15 | return strcmp($a[$sort_field], $b[$sort_field]); |
| 16 | } |
| 17 | // do the array sorting |
| 18 | usort($latest_array, 'cmpi'); |
| 19 | // demo output |
| 20 | echo '<pre>'; |
| 21 | print_r($latest_array); |
| 22 | echo '</pre>'; |
| 23 | ?> |
43 hits by 16 users in the last 30 minutes.