【发布时间】:2010-11-16 18:59:20
【问题描述】:
我有以下数据作为关联数组
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);
没有成功。谁能给我一个提示?
【问题讨论】:
标签: php sorting associative-array warnings