【问题标题】:php array format from xml来自xml的php数组格式
【发布时间】:2010-11-01 14:40:35
【问题描述】:
$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');

我怎么会得到这样的输出:

Array ( [0] => SimpleXMLElement 对象 ( [0] => 9 ) [1] => SimpleXMLElement 对象([0] => 8)[2] => SimpleXMLElement 对象 ( [0] => 6 ) [3] => SimpleXMLElement 对象([0] => 5 ) [4] => SimpleXMLElement 对象 ( [0] => 4 ) [5] => SimpleXMLElement 对象 ( [0] => 3 ) [6] => SimpleXMLElement 对象 ( [0] => 2 ) [7] => SimpleXMLElement 对象([0] => 15 ) [8] => SimpleXMLElement 对象 ( [0] => 1 ) [9] => SimpleXMLElement 对象([0] => 0))

我想得到这样的输出:

数组 ( [0] => 8 [1] => 6 [2] => 5 [3] => 4 [4] => 3 [5] => 9 [6] => 2 [7] => 15 [8] => 1 [9] => 0 [10] => )

在没有所有 SimpleXMLElement gubbins 的情况下,我需要进行哪些更改才能获得上述清理后的数组? 干杯, 安迪

【问题讨论】:

    标签: php xml arrays


    【解决方案1】:

    SimpleXML 返回对象而不是数组。你必须转换它,like this guy did here。该页面上有很多这样的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多