Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MongoDB插入的记录不能正常工作_Php_Arrays_Mongodb_Multidimensional Array - Fatal编程技术网

Php MongoDB插入的记录不能正常工作

Php MongoDB插入的记录不能正常工作,php,arrays,mongodb,multidimensional-array,Php,Arrays,Mongodb,Multidimensional Array,所以,我已经在这段代码上工作了一段时间,但我放弃了,并向你们寻求帮助。我一直在看MongoDB和PHP的文档,但找不到任何东西。我想做的是获取插入记录的示例代码: $obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" ); 目的是为了我的项目(如图所示): 问题是$startCol和$startRow都是数组,每次我想运行文档时都会遇到问题。有什么可笑的简单的东西我错过了吗?提前谢谢 给

所以,我已经在这段代码上工作了一段时间,但我放弃了,并向你们寻求帮助。我一直在看MongoDB和PHP的文档,但找不到任何东西。我想做的是获取插入记录的示例代码:

$obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
目的是为了我的项目(如图所示):

问题是$startCol和$startRow都是数组,每次我想运行文档时都会遇到问题。有什么可笑的简单的东西我错过了吗?提前谢谢

给我带来问题的代码块:

$maxRows= count($currentarray); //Outputs 45
$maxCols= count($currentarray[0]); //Outputs 9
$currentRow=1;
$currentCol=1;

$testing = 1;

    do {
    while ($currentCol<$maxCols){
        $startCol[] = $currentarray[0][$currentCol];
        $startRow[] = $currentarray[$currentRow][$currentCol];
        $currentCol++;
    }

    $obj = array( $startCol => $startRow );
    $collection->insert($obj);
    print_r ($collection);
    if ($currentCol==$maxCols)
    $currentCol=1;
    $currentRow++;
    $testing++;
    //echo "<br />";
    } while ($currentRow<$maxRows);
$maxRows=count($currentarray)//产出45
$maxCols=count($currentarray[0])//产出9
$currentRow=1;
$currentCol=1;
$testing=1;
做{
而($currentCol$startRow);
$collection->insert($obj);
印刷(收集);
如果($currentCol==$maxCols)
$currentCol=1;
$currentRow++;
$testing++;
//回声“
”;
}而($currentRow我遇到的问题是我的输出语句。因此我的答案相当简单。之后,
print\r()
我发现我所有的变量实际上都在存储它们,但在程序结束时我错误地调用了它们。

我首先想到的是$collection似乎没有定义对不起,collection已经定义了,我只是没有发布它。
$maxRows= count($currentarray); //Outputs 45
$maxCols= count($currentarray[0]); //Outputs 9
$currentRow=1;
$currentCol=1;

$testing = 1;

    do {
    while ($currentCol<$maxCols){
        $startCol[] = $currentarray[0][$currentCol];
        $startRow[] = $currentarray[$currentRow][$currentCol];
        $currentCol++;
    }

    $obj = array( $startCol => $startRow );
    $collection->insert($obj);
    print_r ($collection);
    if ($currentCol==$maxCols)
    $currentCol=1;
    $currentRow++;
    $testing++;
    //echo "<br />";
    } while ($currentRow<$maxRows);