note 97711 deleted from function.ksort by danbrown
| From: | danbrown@php.net | Date: | Tue, 04 May 2010 22:54:15 +0000 |
| Subject: | note 97711 deleted from function.ksort by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168941@lists.php.net to get a copy of this message | ||
Note Submitter: tagged at seaoffire dot net
----
Simple recursive function for sorting a multidimensional array by key. Should be able to sort it
with any other sorting functions as well. I may have missed it, but couldn't find anything on
just sorting a large multidimensional array by key for php4.
function multisort($array)
{
while (list($key,$val) = each($array))
{
if (is_array($val))
{
$val = multisort($val);
$array[$key] = $val;
}
}
ksort($array);
return($array);
}
$array = array(z=>1, y=>2, x=>3, w=>array(c=>1, b=>2, a=>3));
Output would be :
Array
(
[w] => Array
(
[a] => 3
[b] => 2
[c] => 1
)
[x] => 3
[y] => 2
[z] => 1
)