且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP - 导入到MySQL数据库时跳过csv的第一行

更新时间:2023-01-21 20:50:58

工作。在您的 foreach 循环拆分之前,您的 $ csvcontent 结果数组到 $ allLines 。然后使用 array_shift 删除此数组的第一个元素(函数也返回此元素,但我们不需要它):

A little change will to the job. Before your foreach loop split your $csvcontent and safe the resulting array to $allLines. Then use array_shift to remove the 1st element of this array (the function also returns this element, but we don’t need it here):

$allLines = split($lineseparator,$csvcontent);
array_shift($allLines); // removes the 1st element

foreach($allLines as $line) {
    [...]