2014-07-01 21 views
0
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

使用'$计数++',而不是'$ ++ count' – Bora

+0

'$节点 - > { 'field_aw_score_'。 $ count} [LANGUAGE_NONE] [0] ['value']' –

+0

@ hek2mgl我以前没见过这样,thx – Bora

回答

3

试试这个:

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