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']
等。一个动态变量。我做错了什么?谢谢。
试试这个:
$node->{'field_aw_score_' . $count}