//比如有这样一个二维数组,它的内容是这样的格式:第一列是索引号,第二列是中文名称
$itemIndex[0][0] == 301; $itemIndex[0][1] == "工资";
$itemIndex[1][0] == 302; $itemIndex[0][2] == "公积金";
//...
//希望把它作为参数传递到函数中。
function getqueryString($ndate,$ItemIndex,$dataSrc,$lineIndex)
{
    //...
}但是这样定义的话在函数里使用它的各个元素会出错,提示说未定义的索引
Notice: Undefined offset: 0 in C:\inetpub\wwwroot\test\csv.php on line 47
求解。
试了一下这样定义也不行哈
function getqueryString($ndate,$ItemIndex[][2],$dataSrc,$lineIndex)

解决方案 »

  1.   

    for($i=1;$i<7;$i++)
    getqueryString($i+201201,$ItemIndex,$aData,$i);
      

  2.   

    $itemIndex[1][0] == 302; $itemIndex[0][2] == "公积金";似应为
    $itemIndex[1][0] == 302; $itemIndex[1][2] == "公积金";你在 getqueryString 中是如何使用参数 $ItemIndex 的?
      

  3.   


    //根据item字段的数目生成后半段查询字符串
    function getqueryString($ndate,$ItemIndex,$dataSrc,$lineIndex)
    {
    $strings = ""; $counts = count($ItemIndex);
    $lines = count($dataSrc);
    $columns = count($dataSrc[0]); $ItemIndex = array();
    for($i=0;$i<$columns;$i++)//遍历csv数组的第一行,即各列的字段名
    {
    $value = $dataSrc[0][$i];
    for($j=0;$j<$counts;$j++)//遍历工资条目,查询对应中文的索引号
    {
    if($value == $ItemIndex[$j][1]) //就是在这里使用出错的,未定义的索引号
    {
    $itemlist[] = sprintf("item%d",$ItemIndex[$j][0]); //如果有则显示itemXX
    break;
    }
    }
    if($j >= $counts) //没有找到匹配项
    $itemlist[] = "nomatch";
    } for($j=1;$j<$columns;$j++)
    {
    if($itemlist[$j-1] != "nomatch")
    {
    $strings .= $itemlist[$j-1];
    $strings .= "=";
    $strings .= $dataSrc[$lineIndex][$j];
    $strings .= ",";
    }
    }
    $strings = substr($strings,0,strlen($strings)-1);//去掉末尾的一个逗号
    $strings .= " WHERE nDate=".$ndate;
    echo "<br />".$strings."<br />"; //输出测试
    }
      

  4.   

    原来多谢了一行这个呀 :)
    $ItemIndex = array();