Php array problem object (SimpleXMLElement) [1]
Public 'book' =>
Array (size = 3)
0 =>
Object (SimpleXMLElement) [2]
Public '@ attributes' =>
Array (size = 1)
...
Public 'name' => string 'php' (length = 3)
Public 'price' => string '20. 0' (length = 4)
1 =>
Object (SimpleXMLElement) [3]
Public '@ attributes' =>
Array (size = 1)
...
Public 'name' => string 'xml' (length = 3)
Public 'price' => string '20. 3' (length = 4)
2 =>
Object (SimpleXMLElement) [4]
Public '@ attributes' =>
Array (size = 1)
...
Public 'name' => string 'c # '(length = 2)
Public 'price' => string '20. 1' (length = 4)
$ Xml = file_get_contents ("book. xml ");
$ Simple = new SimpleXMLElement ($ xml );
Why not use $ simple ['book'] ['name']; in this case, you can only use $ simple-> book-> name. I beg to hear from you
Reply to discussion (solution)
Because it is an object!
Didn't you see an object (SimpleXMLElement?
Object (SimpleXMLElement) indicates an object of the impleXMLElement type.
Thank you!
$ Simple = json_decode (json_encode (simplexml_load_string ($ xml, 'simplexmlelement', LIBXML_NOCDATA), true); // converts the string to an array.