引用动态变量?

时间:2014-07-01 13:14:35

标签: php

for ($count = 1; $count <= 5; ++$count) {
  $test = ${'node->field_aw_score_' . $count}[LANGUAGE_NONE][0]['value'];
  echo $test;
}

引发错误:

Notice: Undefined variable: node->field_aw_score_1
Notice: Undefined variable: node->field_aw_score_2
Notice: Undefined variable: node->field_aw_score_3
Notice: Undefined variable: node->field_aw_score_4
Notice: Undefined variable: node->field_aw_score_5

但是,变量确实存在。我想参考:

$node->field_aw_score_1[LANGUAGE_NONE][0]['value']

然后

$node->field_aw_score_2[LANGUAGE_NONE][0]['value']

等。一个动态变量。我究竟做错了什么?感谢。

1 个答案:

答案 0 :(得分:3)

请改为尝试:

$node->{'field_aw_score_' . $count}