这里的简单问题。为什么会出错?
for ($k = 1; $k < 17; $k++){
echo $result[0]->answer_."$k";
}
编辑:$ result的内容:
数组([0] =&gt; stdClass对象([entry_id] =&gt; 37 [answer_1] =&gt; 20-24岁[answer_2] =&gt;否[answer_3] =&gt;是[answer_4] = &gt;没有[answer_5] =&gt; 236.7 [answer_6] =&gt;理想的血压 - 91和120之间的上限数字,61和80之间的较低数字[answer_7] =&gt;不,我没有检查过[ answer_8] =&gt;不,我退出超过10年[answer_9] =&gt;我有时每周得150分钟或更长时间[answer_10] =&gt;每天2-5小时[answer_11] =&gt;每天[ answer_12] =&gt;经常或不经常[answer_13] =&gt;每天[answer_14] =&gt;一周3-4天[answer_15] =&gt;从不[answer_16] =&gt;帝国))
答案 0 :(得分:0)
尝试
for ($k = 1; $k < 17; $k++){
echo $result[0]->{'answer_'.$k};
}
根据以下mpen的评论更新