【发布时间】:2012-07-11 11:52:16
【问题描述】:
有没有更优雅的方式将 SimpleXML 属性转义到数组中?
$result = $xml->xpath( $xpath );
$element = $result[ 0 ];
$attributes = (array) $element->attributes();
$attributes = $attributes[ '@attributes' ];
我真的不想为了提取键/值对而循环遍历它。我所需要的就是将它放入一个数组中,然后将其传递。我原以为attributes() 默认会这样做,或者至少可以选择。但是我什至无法在任何地方找到上述解决方案,我必须自己弄清楚。我是不是把这件事复杂化了?
编辑:
在确定访问@attributes 数组是否安全之前,我仍在使用上述脚本。
【问题讨论】:
标签: php arrays attributes simplexml