0
我有這樣的代碼:如何通過多個函數調用來保存這個變量?
$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
返回到原來的循環,並解析它通過沒有運氣。
u能解釋這樣對我? – buymypies 2011-05-10 14:37:25
http://php.net/manual/en/language.references.pass.php @Emil只是輸入:) – Chris 2011-05-10 14:38:49
你可以閱讀手冊中的參考資料:http://php.net/manual /en/language.references.php – 2011-05-10 14:38:59