Reputation: 53
I'm writing to you today because I have an issue with sorting my javascript array, I show you ;
In my php script, I json_encode my data.
$data[$value->id_fiche] = $nom . $prenom . $societe;
Here is an example of what appears when I die(var_dump($data)), before the json_encode($data) :
array(6) {
[733]=>
string(24) "ABAD Juan [123 MATIERES]"
[734]=>
string(13) "Abassi Denise"
[735]=>
string(13) "ABBAS Ibtisem"
[736]=>
string(14) "ABEYTUA Alvaro"
}
}
In my js file, I must add options in my select thanks to $.each(data, function (i, item)
But options aren't added in the right order, the $.each function orders by $value->id_fiche.
How can I sort my data.contact by values instead of keys before my $.each function ?
EDIT : in other ways, is it possible for the jquery function $.each to work in values order instead of keys order?
Thank you !
Upvotes: 1
Views: 161
Reputation: 53
I finally decided to work like that in my php script code :
$data[$nom . $prenom . $value->id_fiche] = $nom . $prenom . $societe;
Its works like it, I could even just set $data[$nom]= $nom . $prenom . $societe;
but I need the ID later, and having to same name is possible.
I wish I could help someone later with it :)
Upvotes: 1