這是我的代碼:爲什麼SimpleXML在我使用它時將數組更改爲數組的第一個元素?
$string = <<<XML
<?xml version='1.0'?>
<test>
<testing>
<lol>hello</lol>
<lol>there</lol>
</testing>
</test>
XML;
$xml = simplexml_load_string($string);
echo "All of the XML:\n";
print_r $xml;
echo "\n\nJust the 'lol' array:";
print_r $xml->testing->lol;
輸出:
All of the XML:
SimpleXMLElement Object
(
[testing] => SimpleXMLElement Object
(
[lol] => Array
(
[0] => hello
[1] => there
)
)
)
Just the 'lol' array:
SimpleXMLElement Object
(
[0] => hello
)
爲什麼它僅輸出[0],而不是整個陣列?我沒有明白。
這是否幫助您解決您的問題? –
@Yattatron這並不回答問題的「原因」。如你所說,'$ lol [1]'=「there」和'$ lol [0]'=「hello」,爲什麼'print_r($ lol)'不能打印出'0 =>「hello」, 1 => 「有」'?? – chiliNUT
@chiliNUT你有一個非常有用的觀點。我會思考並稍微修改我的答案。 –