dougou8573 2014-10-26 01:53
浏览 37
已采纳

PHP - 删除数组中的第一个结果[重复]

This question already has an answer here:

I was wondering if someone could help me out.

I have a function that imports a CSV into an array, but i need to remove the first line with the

My CSV is formatted like so:

lat,lng,id
-34.837834,1387457,2

and so on, you get the ID

My function looks like this

private function getArrayFromCsv($file,$delimiter)
{ 

    if (($handle = fopen($file, "r")) !== FALSE) { 

        $i = 0; 
        while (($lineArray = fgetcsv($handle, 4000, $delimiter)) !== FALSE) { 

            for ($j=0; $j<count($lineArray); $j++) { 

                $dataArray[$i][$j] = $lineArray[$j]; 

            } 

            $i++; 

        } 

        fclose($handle); 

    } 

    return $dataArray; 

}

The array that is outputted is as follows:

Array
(
    [0] => Array
        (
            [0] => lat
            [1] => lng
            [2] => id
        )

    [1] => Array
        (
            [0] => -34.837834
            [1] => 1387457
            [2] => 2

and so on .....

How do i go about removing the array that shows the lat,lng,id and start from the next line in the CSV?

Cheers,

</div>
  • 写回答

2条回答 默认 最新

  • dow57588 2014-10-26 01:56
    关注

    To remove an element from an array,
    unset($dataArray[0]);
    Note that the other element indexes are the same.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 手机连接电脑热点显示无ip分配
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大