Php 如何通过多个函数调用保留此变量?

Php 如何通过多个函数调用保留此变量?,php,arrays,Php,Arrays,我有以下代码: $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 = $q

我有以下代码:

$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;
}
函数多线程响应($data,$ID,$k){
$j=1;
while($answers=mysql\u fetch\u assoc($data))
{       
$as=$answers['text_value'];
回声“;
回声“”$j.“$as
”; $k++; $j++; } 返回; }
我想做的基本上是每次调用
multi_response()
$k
都是从上次调用的位置继续,而不是从0开始
$k
基本上是我的索引值,如果它重置为0,则会覆盖数组中以前的数据

我一直在尝试将
$k
返回到原始循环,并对其进行解析,但没有成功。

通过引用发送$k:

function multi_response($data, $ID, &$k){
   //rest of function here ...
}

@Emil刚打出来:)你可以阅读手册中的参考资料: