在制作PHPExcel Reader时不能使用标量作为数组

$file = 'upload/'.$filename;

    //read file from path
    $objPHPExcel = PHPExcel_IOFactory::createReader('Excel2007');
    $objPHPExcel->setReadDataOnly(true);
    $objPHPExcel = $objPHPExcel->load($file);
    $objWorksheet = $objPHPExcel->getActiveSheet();

    $highestRow = $objWorksheet->getHighestRow();
    $highestColumn = $objWorksheet->getHighestColumn();
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

    //$row = array();

    for($row=1; $row <= $highestRow; ++$row){
        for($col=0; $col <= $highestColumnIndex; ++$col){
        $row[$col] = $objWorksheet->getCellByColumnAndRow($col,$row)->getValue();
    }
    }
        echo "<pre>";print_r($row[$col]);echo "</pre>";

Here what is wrong with this $row. it tells me that the value type of $row is scalar. I am using array to put any cell from excel into my html.

I need to put this data into my mysql database. I'am using a Excel sheet, the sample sheet is :

(nama_lengkap, tempat_lahir, provinsi_lahir) ---> as header (Anak pertama, Jakarta, DKI) (Anak kedua, Bandung, Jawa Barat) (Anak ketiga, Semarang, Jawa Tengah)

Imagine table data:

| id | nama        | tempat_lahir | provinsi_lahir |

|----|-------------|--------|-------|

| 1  | John | Semarang  | Jawa tengah    |

| 2  | Meresa | Bandung | Jawa Barat    |

| 3  | Mike  | Jakarta   | Dki    |

Another everything is fine. But you are overwriting value in $row again and again within for loop. Here is the code should look like:

$file = 'upload/' . $filename;
//read file from path
$objPHPExcel = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel->setReadDataOnly(true);
$objPHPExcel = $objPHPExcel->load($file);
$objWorksheet = $objPHPExcel->getActiveSheet();

$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

$excelData = array();

for ($row = 1; $row <= $highestRow; ++$row) {
    for ($col = 0; $col <= $highestColumnIndex; ++$col) {
        $excelData[$row][$col] = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
    }
}
echo "<pre>";
print_r($excelData);
echo "</pre>";

Take an array $excelData and store data from excel sheet in it.