我有这段代码:
$k = 0;
//loop through every question present in query results and run function to present the different question structures
while ($qs = mysql_fetch_assoc($get_questions))
{
$type = $qs['item_type'];
$item_id = $qs['item_id'];
$question = $qs['question_text'];
$question_2 = $qs['question_text_2'];
present_question($item_id, $type, $question, $question_2, $i, $k);
$i ++;
$ids[] = $item_id;
}
现在跳过中间的开关盒,它可以最终完成这个功能:
function multi_response($data, $ID, $k){
$j = 1;
while ($answers = mysql_fetch_assoc($data))
{
$as = $answers['text_value'];
echo "<input name='multi_response[$k][id]' type='hidden' value='$ID'>";
echo "<strong>".$j. ".</strong><input type='checkbox' name='multi_response[$k][answer]' value='$as'> $as</br>";
$k++;
$j++;
}
return;
}
我想要做的事情基本上是每次调用multi_response()
时,$k
将从最后一次而不是从0继续。$k
基本上是我的索引值,如果是重置为0,它会覆盖数组multi_response[][]
我一直试图将$k
返回到原始循环并通过它解析它而没有运气。
答案 0 :(得分:2)
通过引用发送$ k:
function multi_response($data, $ID, &$k){
//rest of function here ...
}