note 79697 deleted from function.usort by felipe
| From: | felipe@php.net | Date: | Sun, 16 Dec 2007 01:03:44 +0000 |
| Subject: | note 79697 deleted from function.usort by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133609@lists.php.net to get a copy of this message | ||
Note Submitter: johndapunk at nospamo dot gmail dot com
----
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() );
?>