は私のコードです: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 => "there" '?? – chiliNUT
@chiliNUTあなたは非常に有効なポイントを持っています。私は思って、私の答えをちょっと修正するつもりです。 –