0

この多次元配列を並べ替える必要がありますが、このサイトや友人の Google で見つけたものでは、正しい解決策にたどり着くことができませんでした。

$url = file_get_contents('http://api.petfinder.com/shelter.getPets?key=&id=&status=A&output=full&count=999');
$xml = simplexml_load_string($url); 
// this is the returned array (see below for example)

foreach($xml->pets->pet as $pet) { 
// ->pet, or $pet is what needs to be sorted
    $data['id'] = (string)$pet->id;
}

上記の API 呼び出しによって返される配列の例を次に示します...

SimpleXMLElement Object
(
[header] => SimpleXMLElement Object
    (
        [status] => SimpleXMLElement Object
            (
                [code] => 100
            )
    )
[lastOffset] => 82
[pets] => SimpleXMLElement Object
    (
        [pet] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [id] => 10595710
                        [name] => Lizzie
                        [animal] => Dog
                        [options] => SimpleXMLElement Object
                            (
                                [option] => Array
                                    (
                                        [0] => altered
                                        [1] => hasShots
                                        [2] => housebroken
                                    )
                            )
                        [lastUpdate] => 2012-10-11T15:19:05Z
                        [media] => SimpleXMLElement Object
                            (
                                [photos] => SimpleXMLElement Object
                                    (
                                        [photo] => Array
                                            (
                                                [0] => http://photos.petfinder.com/photos/US/NC/NC416/10595710/NC416.10595710-1-x.jpg
                                                [1] => http://photos.petfinder.com/photos/US/NC/NC416/10595710/NC416.10595710-1-fpm.jpg
                                            )
                                    )
                            )
                        [contact] => SimpleXMLElement Object
                            (
                                [email] => jghfjhgf
                            )
                    )
                [1] => SimpleXMLElement Object
                    (
                        [id] => 11036032
                        [name] => Buddy
                        [animal] => Dog
                        [breeds] => SimpleXMLElement Object
                            (
                                [breed] => Array
                                    (
                                        [0] => Terrier
                                        [1] => Black Labrador Retriever
                                    )

                            )
                        [options] => SimpleXMLElement Object
                            (
                                [option] => Array
                                    (
                                        [0] => altered
                                        [1] => hasShots
                                        [2] => housebroken
                                    )
                            )
                        [lastUpdate] => 2012-10-11T15:19:05Z
                        [media] => SimpleXMLElement Object
                            (
                                [photos] => SimpleXMLElement Object
                                    (
                                        [photo] => Array
                                            (
                                                [0] => http://photos.petfinder.com/photos/US/NC/NC416/11036032/NC416.11036032-1-x.jpg
                                                [1] => http://photos.petfinder.com/photos/US/NC/NC416/11036032/NC416.11036032-1-fpm.jpg
                                            )
                                    )
                            )
                        [contact] => SimpleXMLElement Object
                            (
                                [email] => kfkhgkhjg
                            )
                    )
                [2] => SimpleXMLElement Object ...

ペットの名前または「lastUpdate」エントリでアルファベット順に並べ替えることができる必要があります。これらは別々のソート方法になります。

4

0 に答える 0