note 46549 deleted from function.usort by sean

From: Date: Fri, 15 Oct 2004 03:42:36 +0000
Subject: note 46549 deleted from function.usort by sean
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78570@lists.php.net to get a copy of this message
Note Submitter: skycrack at 126 dot com ---- <?php class SortInClass { private $arr = array( array('id' => '1', 'title' => 'test1') , array('id' => '6', 'title' => 'test2') , array('id' => '3', 'title' => 'test3') , array('id' => '231', 'title' => 'test4') , array('id' => '451', 'title' => 'test5') , array('id' => '2341', 'title' => 'tes6t') , array('id' => '241', 'title' => 'tes7t') , array('id' => '41', 'title' => 'test8') , array('id' => '21', 'title' => 'test9') ); private function sortArr($a, $b) { if ( $a['id'] == $b['id'] ) return 0; return ( $a['id'] > $b['id'] ) ? -1 : 1; } public function getLastData($num = '5') { usort($this->arr, array('SortInClass', 'sortArr')); return array_slice($this->arr, 0, $num); } } $test = new SortInClass; echo "<pre>"; print_r($test->getLastData(3)); echo "</pre>"; ?> ---- Reason: useless example

« previous php.notes (#78570) next »