First use a piece of code to reproduce the problem
At first glance, the result is very confusing:
Copy the code The code is as follows:
$string = <<
EOF;
$data = simplexml_load_string($string);
print_r($data);
print_r($data->foo);
?>
Copy Code The code is as follows:
SimpleXMLElement Object
(
[foo] => Array
(
[0] => SimpleXMLElement Object
(
[bar] => hello
)
[1] => ; SimpleXMLElement Object
(
[bar] => world
)
)
)
SimpleXMLElement Object
(
[bar] => hello
)
Copy the code The code is as follows:
foreach ($data->foo as $v) print_r($v);
foreach ($data->children() as $ v) print_r($v);
The above introduces the instructions for using the simplexml_load_string function in too simple too naive PHP, including the content of too simple too naive. I hope it will be helpful to friends who are interested in PHP tutorials.