我在 foreach 循环期间创建了一个数组数组(我认为):
$collectGroup = array();
foreach ($topTenList->searchResult->item as $group) {
$collectGroup['title'] = $group->title;
$collectGroup['price'] = $group->sellingStatus->convertedCurrentPrice;
$collectGroup['image'] = $group->galleryURL;
$collectGroup['url'] = $group->viewItemURL;
}
var 转储数组输出:
array(4) {
["title"]=>
object(SimpleXMLElement)#13 (1) {
[0]=>
string(74) "title 1"
}
["price"]=>
object(SimpleXMLElement)#16 (2) {
["@attributes"]=>
array(1) {
["currencyId"]=>
string(3) "GBP"
}
[0]=>
string(9) "1500000.0"
}
["image"]=>
object(SimpleXMLElement)#14 (1) {
[0]=>
string(63) "http://www.website.com/image1.jpg"
}
["url"]=>
object(SimpleXMLElement)#15 (1) {
[0]=>
string(140) "http://www.website.com"
}
}
array(4) {
["title"]=>
object(SimpleXMLElement)#11 (1) {
[0]=>
string(80) "title 2"
}
["price"]=>
object(SimpleXMLElement)#12 (2) {
["@attributes"]=>
array(1) {
["currencyId"]=>
string(3) "GBP"
}
[0]=>
string(9) "8000088.0"
}
["image"]=>
object(SimpleXMLElement)#17 (1) {
[0]=>
string(63) "http://www.website.com/image2.jpg"
}
["url"]=>
object(SimpleXMLElement)#16 (1) {
[0]=>
string(140) "http://www.website.com"
}
}
我现在想做的是按价格降序对数组中的数组进行排序。所以在这种情况下,它应该具有价格为 8000088.0 的数组高于价格为 1500000.0 的数组。我努力了:
ksort($collectGroup['price'], SORT_NUMERIC);
但没有运气,请帮助