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;
}
}
我收到以下警告:
Warning: uasort() expects parameter 2 to be a valid callback,
no array or string given in
C:\xampp\htdocs\news\admin\functions.php on line 554.
第 554 行包含uasort($posts_array, $this->cmp)
.
在哪里使用字符串或数组以及以什么方式使用?
EDIT: 如果我用uasort($posts_array, array($this, 'cmp'));
,我收到以下警告:
uasort() expects parameter 2 to be a valid callback,
array must have exactly two members in
C:\xampp\htdocs\news\admin\functions.php on line 554
你必须这样称呼它:
uasort($posts_array, Array ( $this, 'cmp');
以下链接解释了如何在 PHP 中构造有效的回调:http://www.php.net/manual/en/language.types.callable.php http://www.php.net/manual/en/language.types.callable.php
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)