2012-05-19 86 views
1
echo $xml->SLOT1->Effect; 
echo $xml->SLOT2->Effect; 
echo $xml->SLOT3->Effect; 

有没有办法通过使用for循环来简化此操作?我试过,但它没有回声:SimpleXML动态元素名称

for ($x = 1; $x <= 3; $x++) { 
    echo $xml->SLOT[$x]->Effect; 
} 

回答

3

您可以使用

$xml->{"SLOT".$x}->Effect; 
+0

真棒感谢。 – Norse

+0

不客气。 –

1
for ($x = 1; $x <= 3; $x++) { 
    echo $xml->{SLOT.$x}->Effect; 
} 
+0

哈哈。 @ tpaksu打我吧 – pogeybait

+0

下次可能:) –