note 42164 added to function.array-multisort

From: Date: Thu, 06 May 2004 02:46:42 +0000
Subject: note 42164 added to function.array-multisort
Groups: php.notes 
Request: Send a blank email to php-notes+get-69262@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.array-multisort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42164 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42164&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42164&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69262) next »