note 42164 deleted from function.array-multisort by aidan

From: Date: Sun, 03 Oct 2004 10:38:12 +0000
Subject: note 42164 deleted from function.array-multisort by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77787@lists.php.net to get a copy of this message
Note Submitter: Radley Smith ---- Here's the code I came up with for sorting a multi-dimensional array by the specified key: <?php function multisort(&$array, $sortby, $order='asc') { foreach($array as $val) { $sortarray[] = $val[$sortby]; } $c = $array; $const = $order == 'asc' ? SORT_ASC : SORT_DESC; $s = array_multisort($sortarray, $const, $uselessbullshit, $const); $array = $c; return $s; } ?> array_multisort doesn't seem to work with references, so I just made a copy then assigned the copy to the reference later.

« previous php.notes (#77787) next »