PHP对象变量的变量名? [英] PHP Object Variable variables name?
本文介绍了PHP对象变量的变量名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从1到10的循环,并在其中打印值
I have a loop that goes from 1 to 10 and prints values in
$entity_object->field_question_1
到10左右...
$entity_object->field_question_1
,$entity_object->field_question_2
等
我想在此循环中打印此代码,如何获取变量?我尝试做
And I want to print this in this loop, how can I get the variable? I tried doing the
$var = "entity_object->field_question_".$i;
print $$var;
但这没用...
如何获取这些值?
推荐答案
这应该有效:
$var="field_question_$i";
$entity_object->$var;
这篇关于PHP对象变量的变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文