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;
}
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;
}
您可以使用
$xml->{"SLOT".$x}->Effect;
for ($x = 1; $x <= 3; $x++) {
echo $xml->{SLOT.$x}->Effect;
}
哈哈。 @ tpaksu打我吧 – pogeybait
下次可能:) –
真棒感谢。 – Norse
不客气。 –