我有一个从 1 到 10 的循环并在其中打印值
$entity_object->field_question_1
到 10 所以...
$entity_object->field_question_1
、$entity_object->field_question_2
等
我想在这个循环中打印这个,我怎样才能得到这个变量?我试着做
$var = "entity_object->field_question_".$i;
print $$var;
但这没有用......
我怎样才能得到这些值?
最佳答案
这应该可行:
$var="field_question_$i";
$entity_object->$var;
关于PHP Object Variable变量名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10919011/