1
我的代碼
<?php
$a = 'node'
$xml = simplexml_load_file('config.xml');
echo $xml->node //work fine
echo $xml->{$a}; //also work fine
?>
<?php
$a = 'node[0]'
$xml = simplexml_load_file('config.xml');
echo $xml->node[0] //work fine
echo $xml->{$a}; //DOESNT WORK!
?>
爲什麼節點[0]在一個變量不行?我該如何解決?
$ a ='node'; $ b ='0'; $ num =(int)$ b; echo $ xml - > {$ a} [$ num]; //很好地工作謝謝 – user1721470