note 46549 added to function.usort

From: Date: Fri, 15 Oct 2004 03:32:48 +0000
Subject: note 46549 added to function.usort
Groups: php.notes 
Request: Send a blank email to php-notes+get-78568@lists.php.net to get a copy of this message
<?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>"; ?> ---- Manual Page -- http://www.php.net/manual/en/function.usort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46549 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46549&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46549&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46549&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46549&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46549&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46549&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46549&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78568) next »