我有一个从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;
Run Code Online (Sandbox Code Playgroud)
但那不起作用......
我怎样才能获得这些价值?
Tim*_*ers 40
这应该工作:
$var="field_question_$i";
$entity_object->$var;
Run Code Online (Sandbox Code Playgroud)
小智 20
实际上你需要将变量放在字符串之外,以便这些解决方案能够工作:
$var="field_question_".$i;
$entity_object->$var;
要么
$entity_object->{"field_question_".$i}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21249 次 |
| 最近记录: |