我有一个名为$ excelData的数组数组。用下面的代码 访问阵列索引值
Array (
[0] => Array (
[0] => Array (
[0] => name
[1] => test
[2] => 4
[3] => [email protected]
[4] => it4249
[5] => sha256:1000:
)
)
[1] => Array (
[0] => Array (
[0] => fseconf
[1] => test2
[2] => 3
[3] => [email protected]
[4] => ft9655
[5] => sha256:1000:
)
)
)
,我试图打印第四届指数在每种情况下(即it4249和ft955):的print_r($ excelData)返回以下
$query = "INSERT INTO tblTest (username, fname, surname, year, email) VALUES";
$qPart = array_fill(0, count($excelData), "(?, ?, ?, ?, ?)");
$query .= implode(",",$qPart);
$sth = $dbh->prepare($query);
$i = 1;
print_r($excelData);
echo "<br />";
echo "<br />";
Foreach($excelData As $Row){
echo "Username: ".$Row[0][4];
echo "<br />";
echo "<br />";
$sth->bindValue($i++, $Row[0][4]);
$sth->bindValue($i++, $Row[0][0]);
$sth->bindValue($i++, $Row[0][1]);
$sth->bindValue($i++, $Row[0][2]);
$sth->bindValue($i++, $Row[0][3]);
}
但它只是简单地打印it4249。为什么这不起作用,我该如何解决这个问题?
编辑:
更改我的循环引用如下解决我的问题通过,但我不知道为什么 - 任何解释?
Foreach($excelData As &$Row){
}
它适用于我,所以还有其他错误。 – Michel
代码适合我。 –
哦奇怪 - 我已经在循环中添加了其余的代码,以防有其他事情发生? – db579