本文介绍了排序simplexml数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个simplexml数组,我设法通过Google上的示例开始工作.现在我必须对数组进行排序.
I have this simplexml array which i managed to get working from examples on google. now i have to sort the array.
这就是我所拥有的.
$url = 'http://api.trademe.co.nz/v1/Member/2128687/Listings/All.xml';
$xml = simplexml_load_file($url);
foreach($xml->List->Listing as $list){
echo $list->EndDate;
echo '<br/>';
}
一切正常.我想按最接近结束日期的顺序对其进行排序.
everything works as it should like that. i want to sort it by closest to end date.
ive尝试了所有我能找到的示例,但我一直都没有白屏.
ive tried all the examples i can find and i just keep getting white screen of nothing.
请帮助!
推荐答案
function cmp($a, $b)
{
$a = strtotime($a->EndDate);
$b = strtotime($b->EndDate);
if ($a == $b)
{
return 0;
}
return ($a < $b) ? -1 : 1;
}
uasort($xml->List->Listing, 'cmp');
print_r($array);
这篇关于排序simplexml数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!