先用一段代码重现一下问题
乍一看,结果很让人费解:
复制代码 代码如下:
$string =
EOF;
$data = simplexml_load_string($string);
print_r($data);
print_r($data->foo);
?>
复制代码 代码如下:
SimpleXMLElement Object
(
[foo] => Array
(
[0] => SimpleXMLElement Object
(
[bar] => hello
)
[1] => SimpleXMLElement Object
(
[bar] => world
)
)
)
SimpleXMLElement Object
(
[bar] => hello
)
复制代码 代码如下:
foreach ($data->foo as $v) print_r($v);
foreach ($data->children() as $v) print_r($v);