note 97711 added to function.ksort

From: Date: Tue, 04 May 2010 16:22:34 +0000
Subject: note 97711 added to function.ksort
Groups: php.notes 
Request: Send a blank email to php-notes+get-168929@lists.php.net to get a copy of this message
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 ) ---- Server IP: 64.71.164.2 Probable Submitter: 216.215.144.201 ---- Manual Page -- http://www.php.net/manual/en/function.ksort.php Edit -- https://master.php.net/note/edit/97711 Del: integrated -- https://master.php.net/note/delete/97711/integrated Del: useless -- https://master.php.net/note/delete/97711/useless Del: bad code -- https://master.php.net/note/delete/97711/bad+code Del: spam -- https://master.php.net/note/delete/97711/spam Del: non-english -- https://master.php.net/note/delete/97711/non-english Del: in docs -- https://master.php.net/note/delete/97711/in+docs Del: other reasons-- https://master.php.net/note/delete/97711 Reject -- https://master.php.net/note/reject/97711 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168929) next »