Bonjour,
J'aimerai récupérer l'élément correspondant à un id.
ex: je veux le libelle de ID 2, ça me retournerais : Albania.
Et faire ça sans faire de boucle biensur.
j'ai pour le moment :
1 2 3
|
$xml = simplexml_load_file($fichier);
$list_country = $xml->xpath('//country'); |
Voilà ce que me retourne var_dump($list_country) :
array(80) { [0]=> object(SimpleXMLElement)#2 (2) { ["id_country"]=> string(1) "2" ["libelle"]=> string(7) "Albania" } [1]=> object(SimpleXMLElement)#3 (2) { ["id_country"]=> string(1) "3" ["libelle"]=> string(7) "Algeria" } [2]=> object(SimpleXMLElement)#4 (2) { ["id_country"]=> string(1) "9" ["libelle"]=> string(9) "Argentina" } [3]=> object(SimpleXMLElement)#5 (2) { ["id_country"]=> string(2) "12" ["libelle"]=> string(9) "Australia" } [4]=> object(SimpleXMLElement)#6 (2) { ["id_country"]=> string(2) "13" ["libelle"]=> string(7) "Austria" } [5]=> object(SimpleXMLElement)#7 (2) { ["id_country"]=> string(2) "18" ["libelle"]=> string(8) "Barbados" } [6]=> object(SimpleXMLElement)#8 (2) { ["id_country"]=> string(2) "19" ["libelle"]=> string(7) "Belarus" } [7]=> object(SimpleXMLElement)#9 (2) { ["id_country"]=> string(2) "20" ["libelle"]=> string(7) "Belgium" } [8]=> object(SimpleXMLElement)#10 (2) { ["id_country"]=> string(2) "23" ["libelle"]=> string(7) "Bermuda" } [9]=> object(SimpleXMLElement)#11 (2) { ["id_country"]=> string(2) "29" ["libelle"]=> string(6) "Brazil" }}
Merci de votre aide.
Partager