$objDOM = new SimpleXMLElement(XML_FILE_NAME, null, true); // load SimpleXML
$current = $objDOM->xpath('picture');
function sort_current($t1, $t2) {
 return strcmp($t2['id'], $t1['id']); // to sort high > low
 }
usort($current, 'sort_current');为什么我会得到这样的输出:
数组( => SimpleXMLElement Object ( => 9)1 => SimpleXMLElement Object ( => 8)2 => SimpleXMLElement Object ( => 6)3 => SimpleXMLElement Object ( => 5)4 => SimpleXMLElement Object ( => 4)5 => SimpleXMLElement Object ( => 3)6 => Object (2)7 en22# Object ( 15 )8 en25# Object (1)9 en28# Object (0))
我想得到这样的输出:
阵列( => 8 1 => 6 2 => 5 3 => 4 4 => 3 5 => 9 6 => 2 7 => 15 8 => 1 9 => 0 10 => )
如果没有所有的SimpleXMLElement套接字,我需要更改什么才能得到像上面那样的清理数组?干杯,安迪
发布于 2010-11-01 14:43:58
SimpleXML返回对象而不是数组。你必须转换它,就像这家伙在这里做的。这一页上有很多这样的东西。
https://stackoverflow.com/questions/4069870
复制相似问题