note 51088 added to function.sort

From: Date: Sat, 19 Mar 2005 01:55:32 +0000
Subject: note 51088 added to function.sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-86677@lists.php.net to get a copy of this message
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>"; ?> ---- Manual Page -- http://www.php.net/manual/en/function.sort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51088 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51088&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51088&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51088&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51088&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51088&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51088&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86677) next »