echo $xml->SLOT1->Effect;
echo $xml->SLOT2->Effect;
echo $xml->SLOT3->Effect;
有没有办法通过使用for
循环来简化这一点?我试过这个,但它没有任何回声:
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;
}