i have following data as an associative array
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);
但都没有成功。有人能给我提示吗?