我需要对这个多维数组进行排序,我在这个网站上或通过我的朋友 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”条目的字母顺序排序。这些将是单独的排序方法。