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 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi