i wurden folgende Daten als assoziatives ArrayPHP "Warnung: usort() [function.usort]: Ungültige Vergleichsfunktion" auf Sortier
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 das Array unter Verwendung von "Label" oder „Gewicht sortiert werden soll "
die Vergleichsfunktion für das Label ist:
function compare_label($a, $b)
{
return strnatcmp($a['label'], $b['label']);
}
und als ich nenne nur die Funktion von einer anderen Funktion:
usort($label, 'compare_label');
var_dump($label);
aber dann bekomme ich die Fehlermeldung und das Array ist nicht sortiert. Ich weiß nicht, was ich falsch mache. Ich habe zu ersetzen versucht:
usort($label, 'compare_label');
mitusort($label, compare_label);
usort($label, 'compare_label');
mitusort($label, $this->compare_label);
ohne Erfolg. Kann mir jemand einen Hinweis geben?
ja, ist eine Elementfunktion ....und es funktioniert! :) – cupakob