我发现了一个PDO的奇怪行为。 当我使用此代码时
$url_array = ['111', '222'];
foreach ($url_array as $key => $url){
$values[] = '(:url'.$key.', :referer'.$key.')';
}
$query = implode(',', $values);
$pdo = $this->createPDO();
$sth = $pdo->prepare("INSERT INTO `tbl_list` (`num`) VALUES " . $query);
foreach ($nums as $key => $num){ <==================
$sth->bindParam(':url'.$key, $num);
}
$sth->execute();
我在桌子上得到222,222。但是当我添加&amp;到了2-d foreach-我的表中有111,222
$url_array = ['111', '222'];
foreach ($url_array as $key => $url){
$values[] = '(:url'.$key.', :referer'.$key.')';
}
$query = implode(',', $values);
$pdo = $this->createPDO();
$sth = $pdo->prepare("INSERT INTO `tbl_list` (`num`) VALUES " . $query);
foreach ($nums as $key => &$num){ <==================
$sth->bindParam(':url'.$key, $num);
}
$sth->execute();
这是什么原因?