j'ai données suivantes comme un tableau associatifPHP « Attention: usort() [function.usort]: fonction de comparaison non valide » sur le tri
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
Je veux trier le tableau en utilisant « label » ou « poids "
la fonction de comparaison pour l'étiquette est:
function compare_label($a, $b)
{
return strnatcmp($a['label'], $b['label']);
}
et que je viens d'appeler la fonction d'une autre fonction:
usort($label, 'compare_label');
var_dump($label);
mais ensuite j'obtiens le message d'erreur et le tableau n'est pas trié. Je ne sais pas, ce que je fais mal. J'ai essayé de remplacer:
usort($label, 'compare_label');
avecusort($label, compare_label);
usort($label, 'compare_label');
avecusort($label, $this->compare_label);
sans succès. Quelqu'un peut-il me donner un indice?
oui, est une fonction membre ....et il fonctionne! :) – cupakob