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
I want to sort the array using "label" or "weight"
The compare function for the label is:
function compare_label($a, $b)
{
return strnatcmp($a['label'], $b['label']);
}
and than i just call the function from another function:
usort($label, 'compare_label');
var_dump($label);
but then i get the error message and the array is not sorted. I don't know, what I'm doing wrong. I've tried to replace:
usort($label, 'compare_label');
withusort($label, compare_label);
usort($label, 'compare_label');
withusort($label, $this->compare_label);
without success. Can someone give me a hint?