note 87548 added to function.sort

From: Date: Wed, 10 Dec 2008 04:14:22 +0000
Subject: note 87548 added to function.sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-147975@lists.php.net to get a copy of this message
A little shorter way to sort an array of objects; with a callback function. <?php function objSort(&$objArray,$indexFunction,$sort_flags=0) { $indices = array(); foreach($objArray as $obj) { $indeces[] = $indexFunction($obj); } return array_multisort($indeces,$objArray,$sort_flags); } function getIndex($obj) { return $obj->getPosition(); } objSort($objArray,'getIndex'); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 129.132.208.20 ---- Manual Page -- http://www.php.net/manual/en/function.sort.php Edit -- https://master.php.net/note/edit/87548 Del: integrated -- https://master.php.net/note/delete/87548/integrated Del: useless -- https://master.php.net/note/delete/87548/useless Del: bad code -- https://master.php.net/note/delete/87548/bad+code Del: spam -- https://master.php.net/note/delete/87548/spam Del: non-english -- https://master.php.net/note/delete/87548/non-english Del: in docs -- https://master.php.net/note/delete/87548/in+docs Del: other reasons-- https://master.php.net/note/delete/87548 Reject -- https://master.php.net/note/reject/87548 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#147975) next »