class DBNews {
public function get_latest_posts($limit){
// code goes here
$posts_array = array();
uasort($posts_array, $this->cmp);
}
public function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
}
I get the following warning :
Warning: uasort() expects parameter 2 to be a valid callback,
no array or string given in
C:\xampp\htdocs
ews\admin\functions.php on line 554.
And the 554th line contains uasort($posts_array, $this->cmp)
.
Where to make use of the string or array and in what way?
EDIT : If I use uasort($posts_array, array($this, 'cmp'));
, I get the following warning:
uasort() expects parameter 2 to be a valid callback,
array must have exactly two members in
C:\xampp\htdocs
ews\admin\functions.php on line 554
If you have >= 5.3 and you're not using the compare method in any other function, you can also use closures:
uasort($posts_array, function($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
});
You have to call it like this:
uasort($posts_array, Array ( $this, 'cmp');
The following link explains how you can construct a valid callback in PHP: http://www.php.net/manual/en/language.types.callable.php
uasort($posts_array, array($this, 'cmp'));