我具有以下数据作为关联数组PHP“警告:usort()[function.usort]:无效比较函数”排序
array
'abc' =>
array
'label' => string 'abc' (length=3)
'weight' => float 3
'wsx' =>
array
'label' => string 'wsx' (length=3)
'weight' => float 1
'qay' =>
array
'label' => string 'qay' (length=3)
'weight' => float 1
'http://test.com' =>
array
'label' => string 'http://test.com' (length=15)
'weight' => float 0
'Nasi1' =>
array
'label' => string 'Nasi1' (length=5)
'weight' => float 0
'fax' =>
array
'label' => string 'fax' (length=3)
'weight' => float 4
我想用“标记”或“重量数组进行排序“
该标签的比较功能是:
function compare_label($a, $b)
{
return strnatcmp($a['label'], $b['label']);
}
,比我只需要调用该函数从另一个功能:
usort($label, 'compare_label');
var_dump($label);
但后来我得到错误消息,数组未被排序。我不知道,我做错了什么。我试图取代:
usort($label, 'compare_label');
与usort($label, compare_label);
usort($label, 'compare_label');
与usort($label, $this->compare_label);
没有成功。有人可以给我一个提示吗?
是的,是一个成员函数....它的工作原理! :) – cupakob 2009-08-04 19:18:09