note 51088 deleted from function.sort by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 10:16:44 +0000 |
| Subject: | note 51088 deleted from function.sort by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196969@lists.php.net to get a copy of this message | ||
Note Submitter: dwatson at planandgrow dot com
----
Here is a recursive use of sort for multi-dim arrays:
<?php
/*Mulsort function recursively sorts a multi-dimensional, numeric array in place,
regardless of how many dimensions it has. The array can be ragged -- not a matrix.
*/
function mulsort(&$a)
{
sort($a);
$c = count($a);
for($i = 0; $i < $c; $i++)
if (is_array($a[$i]))
mulsort($a[$i]);
}
//The following array is just used to demo the mulsort function.
$array_demo = array ( array ( array (333,1,9,8,7,6,5), array (array(1, 'x', 22), 99, 88 ),
-10 ),
array ( array (11, 12, 'a', 'b', 'c'), array (8, 1, 2,-5) ) );
echo "Array before sorting:<br /><pre>";
var_dump($array_demo);
echo "</pre></ br></ br>";
mulsort($array_demo);
echo "Array after sorting:<br /><pre>";
var_dump($array_demo);
echo "</pre>";
?>