note 25360 added to function.usort

From: Date: Fri, 20 Sep 2002 14:29:51 +0000
Subject: note 25360 added to function.usort
Groups: php.notes 
Request: Send a blank email to php-notes+get-37044@lists.php.net to get a copy of this message
If you want to sort an array according to another array acting as a priority list, you can use this function. function listcmp($a, $b) { global $order; foreach($order as $key => $value) { if($a==$value) { return 0; break; } if($b==$value) { return 1; break; } } } $order[0] = "first"; $order[1] = "second"; $order[2] = "third"; $array[0] = "second"; $array[1] = "first"; $array[2] = "third"; $array[3] = "fourth"; $array[4] = "second"; $array[5] = "first"; $array[6] = "second"; usort($array, "listcmp"); print_r($array); -- http://www.php.net/manual/en/function.usort.php http://master.php.net/manage/user-notes.php?action=edit+25360 http://master.php.net/manage/user-notes.php?action=delete+25360 http://master.php.net/manage/user-notes.php?action=reject+25360

« previous php.notes (#37044) next »