note 79697 added to function.usort

From: Date: Sat, 08 Dec 2007 21:48:37 +0000
Subject: note 79697 added to function.usort
Groups: php.notes 
Request: Send a blank email to php-notes+get-132960@lists.php.net to get a copy of this message
In regards to Sid_M, I did not have to use the 'static' keyword with my PHP5 configuration. However, I made my call within the scope of the object. I don't know how you did it. In order to call a compare function within an object's scope, keep it static; don't use 'this'. As my example shows... <?php class foo { public function do_foo() { $a = array( array( 'search_id' => 1, 'relevance' => '.950251' ), array( 'search_id' => 2, 'relevance' => '.869535' ) ); usort( $a, array( 'foo', 'sort_by_relevance' ) ); return $a; } private function sort_by_relevance( $a, $b ) { return ($a['relevance'] < $b['relevance']) ? 1 : -1; } } $foo = new foo; print_r( $foo->do_foo() ); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 65.11.67.118 ---- Manual Page -- http://www.php.net/manual/en/function.usort.php Edit -- https://master.php.net/note/edit/79697 Del: integrated -- https://master.php.net/note/delete/79697/integrated Del: useless -- https://master.php.net/note/delete/79697/useless Del: bad code -- https://master.php.net/note/delete/79697/bad+code Del: spam -- https://master.php.net/note/delete/79697/spam Del: non-english -- https://master.php.net/note/delete/79697/non-english Del: in docs -- https://master.php.net/note/delete/79697/in+docs Del: other reasons-- https://master.php.net/note/delete/79697 Reject -- https://master.php.net/note/reject/79697 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132960) next »