Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Merge/combine(不确定我需要哪个?)如果键[any][0]是相同的数字,则使用php数组_Php_Arrays_Sorting_Array Merge_Array Combine - Fatal编程技术网

Merge/combine(不确定我需要哪个?)如果键[any][0]是相同的数字,则使用php数组

Merge/combine(不确定我需要哪个?)如果键[any][0]是相同的数字,则使用php数组,php,arrays,sorting,array-merge,array-combine,Php,Arrays,Sorting,Array Merge,Array Combine,使用以下代码,我能够将上传的CSV文件转换为php数组 <?PHP function readCSV($csvFile){ $file_handle = fopen($csvFile, 'r'); fgetcsv($file_handle); fgetcsv($file_handle); fgetcsv($file_handle); while (!feof($file_handle) ) { $line_of_text[]

使用以下代码,我能够将上传的CSV文件转换为php数组

    <?PHP
function readCSV($csvFile){
    $file_handle = fopen($csvFile, 'r');
    fgetcsv($file_handle);
    fgetcsv($file_handle);
    fgetcsv($file_handle);
    while (!feof($file_handle) ) {
        $line_of_text[] = fgetcsv($file_handle, 1024);
    }
    fclose($file_handle);
    return $line_of_text;
}


// Set path to CSV file
$csvFile = 'test.csv';

$csv = readCSV($csvFile);
?>

然后我可以使用..查看页面上的数组

<?php echo '<pre>';
print_r($csv);
echo '</pre>'; ?> 

这将按如下方式输出数组(看起来像真实数据,但已被匿名化)

数组
(
[0]=>阵列
(
[0] => 15304
[1] => 15-04478-27247
[2] =>ersmith0
[3] =>埃里克·史密斯
[4] => myemail@gmail.com
[5] => 
[6] =>2任何关闭
[7] => 
[8] =>曼彻斯特
[9] =>大曼彻斯特
[10] =>m15bb
[11] =>联合王国
[12] =>埃里克·史密斯
[13] => +44 7719 123456
[14] =>27任何接近
[15] => 
[16] =>曼彻斯特
[17] =>大曼彻斯特
[18] =>m15bb
[19] =>联合王国
[20] => 
[21] => 
[22] => 
[23] => 
[24] => 2
[25] => £3.90
[26] => £0.00
[27] => 
[28] => £0.00
[29] => £0.00
[30] => £3.90
[31]=>否
[32]=>贝宝
[33]=>20年1月30日
[34]=>20年1月30日
[35] => 
[36] => 
[37] => 
[38]=>20年1月31日
[39] => 
[40] => 
[41] => 
[42]=>5LD0123456789U
[43]=>英国皇家邮政头等舱
[44] => 
[45] => 
[46] => 
[47]=>否
[48] => 
[49]=>否
[50] => 
[51]=>否
)
[1] =>阵列
(
[0] => 15304
[1] => 15-04478-27247
[2] =>ersmith0
[3] => 
[4] => 
[5] => 
[6] => 
[7] => 
[8] => 
[9] => 
[10] => 
[11] => 
[12] => 
[13] => 
[14] => 
[15] => 
[16] => 
[17] => 
[18] => 
[19] => 
[20] => 302804801330
[21]=>骑自行车的人小心驾驶-有趣的乙烯基贴纸4x4/汽车/卡车/货车/露营车
[22] => 
[23]=>否
[24] => 1
[25] => £1.95
[26] => 
[27] => 
[28] => 
[29] => 
[30] => 
[31] => 
[32] => 
[33]=>20年1月30日
[34] => 
[35] => 
[36] => 
[37] => 
[38]=>20年1月31日
[39]=>否
[40] => 
[41] => 
[42] => 
[43] => 
[44] => 
[45] => 1711351782020
[46] => 
[47] => 
[48] => 
[49] => 
[50] => 
[51] => 
)
[2] =>阵列
(
[0] => 15304
[1] => 15-04478-27247
[2] =>ersmith0
[3] => 
[4] => 
[5] => 
[6] => 
[7] => 
[8] => 
[9] => 
[10] => 
[11] => 
[12] => 
[13] => 
[14] => 
[15] => 
[16] => 
[17] => 
[18] => 
[19] => 
[20] => 302804815489
[21]=>警告骑自行车的人,态度自负风险汽车乙烯基贴纸
[22] => 
[23]=>否
[24] => 1
[25] => £1.95
[26] => 
[27] => 
[28] => 
[29] => 
[30] => 
[31] => 
[32] => 
[33]=>20年1月30日
[34] => 
[35] => 
[36] => 
[37] => 
[38]=>20年1月31日
[39]=>否
[40] => 
[41] => 
[42] => 
[43] => 
[44] => 
[45] => 1711351781020
[46] => 
[47] => 
[48] => 
[49] => 
[50] => 
[51] => 
)
[3] =>阵列
(
[0] => 15305
[1] => 25-04445-36722
[2] =>pod69
[3] =>玛特獾
[4] => martsemailddr34@gmail.com
[5] => 
[6] =>通过Riccione第35/30号
[7] => 
[8] =>Sa Tiacca QUART U.Elena
[9] =>CA
[10] => 09445
[11] =>意大利
[12] =>獾城
[13] => +39 987 654 3211
[14] =>通过Riccione第35/30号
[15] => 
[16] =>Sa Tiacca QUART U.Elena
[17] =>CA
[18] => 09445
[19] =>意大利
[20] => 302667176336
[21]=>2x搞笑汽车和货车或露营车WV睫毛乙烯基贴纸、标志-任何颜色!
[22] => 
[23]=>否
[24] => 2
[25] => £1.99
[26] => £3.14
[27] => 
[28] => £0.00
[29] => £0.00
[30] => £7.12
[31]=>否
[32]=>贝宝
[33]=>20年1月23日
[34]=>20年1月23日
[35]=>20年1月24日
[36] => 
[37] => 
[38]=>20年1月24日
[39]=>是
[40] => 
[41] => 
[42]=>25C157351T688860U
[43]=>英国皇家邮政国际标准
[44] => 
[45] => 1709118816020
[46] => 
[47]=>否
[48] => 
[49]=>否
[50] => 
[51]=>否
)
[4] =>阵列
(
[0] => 15306
[1] => 20-04482-41274
Array
(
    [0] => Array
        (
            [0] => 15304
            [1] => 15-04478-27247
            [2] => ersmith0
            [3] => eric smith
            [4] => myemail@gmail.com
            [5] => 
            [6] => 2 Any Close
            [7] => 
            [8] => Manchester
            [9] => Greater Manchester
            [10] => M1 5BB
            [11] => United Kingdom
            [12] => eric smith
            [13] => +44 7719 123456
            [14] => 27 Any Close
            [15] => 
            [16] => Manchester
            [17] => Greater Manchester
            [18] => M1 5BB
            [19] => United Kingdom
            [20] => 
            [21] => 
            [22] => 
            [23] => 
            [24] => 2
            [25] => £3.90
            [26] => £0.00
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £3.90
            [31] => No
            [32] => PayPal
            [33] => 30-Jan-20
            [34] => 30-Jan-20
            [35] => 
            [36] => 
            [37] => 
            [38] => 31-Jan-20
            [39] => 
            [40] => 
            [41] => 
            [42] => 5LD0123456789U
            [43] => Royal Mail 1st Class
            [44] => 
            [45] => 
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

    [1] => Array
        (
            [0] => 15304
            [1] => 15-04478-27247
            [2] => ersmith0
            [3] => 
            [4] => 
            [5] => 
            [6] => 
            [7] => 
            [8] => 
            [9] => 
            [10] => 
            [11] => 
            [12] => 
            [13] => 
            [14] => 
            [15] => 
            [16] => 
            [17] => 
            [18] => 
            [19] => 
            [20] => 302804801330
            [21] => CAUTION DRIVEN BY A BIKER  - Fun Vinyl Decal Sticker 4x4/Car/Lorry/Van/Camper
            [22] => 
            [23] => No
            [24] => 1
            [25] => £1.95
            [26] => 
            [27] => 
            [28] => 
            [29] => 
            [30] => 
            [31] => 
            [32] => 
            [33] => 30-Jan-20
            [34] => 
            [35] => 
            [36] => 
            [37] => 
            [38] => 31-Jan-20
            [39] => No
            [40] => 
            [41] => 
            [42] => 
            [43] => 
            [44] => 
            [45] => 1711351782020
            [46] => 
            [47] => 
            [48] => 
            [49] => 
            [50] => 
            [51] => 
        )

    [2] => Array
        (
            [0] => 15304
            [1] => 15-04478-27247
            [2] => ersmith0
            [3] => 
            [4] => 
            [5] => 
            [6] => 
            [7] => 
            [8] => 
            [9] => 
            [10] => 
            [11] => 
            [12] => 
            [13] => 
            [14] => 
            [15] => 
            [16] => 
            [17] => 
            [18] => 
            [19] => 
            [20] => 302804815489
            [21] => Warning Biker With an Attitude Annoy At Your Own Risk Car Vinyl Decal Sticker
            [22] => 
            [23] => No
            [24] => 1
            [25] => £1.95
            [26] => 
            [27] => 
            [28] => 
            [29] => 
            [30] => 
            [31] => 
            [32] => 
            [33] => 30-Jan-20
            [34] => 
            [35] => 
            [36] => 
            [37] => 
            [38] => 31-Jan-20
            [39] => No
            [40] => 
            [41] => 
            [42] => 
            [43] => 
            [44] => 
            [45] => 1711351781020
            [46] => 
            [47] => 
            [48] => 
            [49] => 
            [50] => 
            [51] => 
        )

    [3] => Array
        (
            [0] => 15305
            [1] => 25-04445-36722
            [2] => pod69
            [3] => mart badger
            [4] => martsemailddr34@gmail.com
            [5] => 
            [6] => Via Riccione N. 35/30
            [7] => 
            [8] => Sa Tiacca Quartu S. Elena
            [9] => CA
            [10] => 09445
            [11] => Italy
            [12] => Badger Mart
            [13] => +39 987 654 3211
            [14] => Via Riccione N. 35/30
            [15] => 
            [16] => Sa Tiacca Quartu S. Elena
            [17] => CA
            [18] => 09445
            [19] => Italy
            [20] => 302667176336
            [21] => 2x Funny Car & Van or Camper WV Eyelash Vinyl Sticker Decal, Signs - Any Colour!
            [22] => 
            [23] => No
            [24] => 2
            [25] => £1.99
            [26] => £3.14
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £7.12
            [31] => No
            [32] => PayPal
            [33] => 23-Jan-20
            [34] => 23-Jan-20
            [35] => 24-Jan-20
            [36] => 
            [37] => 
            [38] => 24-Jan-20
            [39] => Yes
            [40] => 
            [41] => 
            [42] => 25C157351T6888860U
            [43] => Royal Mail International Standard
            [44] => 
            [45] => 1709118816020
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

    [4] => Array
        (
            [0] => 15306
            [1] => 20-04482-41274
            [2] => wideboiy38887
            [3] => Paul Lastname
            [4] => wideboiysemail@hotmail.co.uk
            [5] => Yellow please
            [6] => 10
            [7] => Broomstick Lane
            [8] => Okehampton
            [9] => Devon
            [10] => EX19 2FT
            [11] => United Kingdom
            [12] => Paul Lastname
            [13] => +44 7866 401983
            [14] => 105
            [15] => Broomstick Lane
            [16] => Okehampton
            [17] => Devon
            [18] => EX19 2FT
            [19] => United Kingdom
            [20] => 302755568952
            [21] => Junglist Soldier Car Window Laptop Wall Gift Drum Bass dnb Jungle Vinyl Sticker
            [22] => 
            [23] => No
            [24] => 1
            [25] => £1.99
            [26] => £0.00
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £1.99
            [31] => No
            [32] => PayPal
            [33] => 01-Feb-20
            [34] => 01-Feb-20
            [35] => 03-Feb-20
            [36] => 
            [37] => 
            [38] => 
            [39] => No
            [40] => 
            [41] => 
            [42] => 7SD68673EE789782X
            [43] => Royal Mail 1st Class
            [44] => 
            [45] => 1711667179020
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

    <!-And so on.....>
Array
(
    [0] => Array
        (
            [0] => 15304
            [1] => 15-04478-27247
            [2] => ersmith0
            [3] => eric smith
            [4] => myemail@gmail.com
            [5] => 
            [6] => 2 Any Close
            [7] => 
            [8] => Manchester
            [9] => Greater Manchester
            [10] => M1 5BB
            [11] => United Kingdom
            [12] => eric smith
            [13] => +44 7719 123456
            [14] => 27 Any Close
            [15] => 
            [16] => Manchester
            [17] => Greater Manchester
            [18] => M1 5BB
            [19] => United Kingdom
            [20] => 
            [21] => Array (
                [0] => CAUTION DRIVEN BY A BIKER  - Fun Vinyl Decal Sticker 4x4/Car/Lorry/Van/Camper
                [1] => Warning Biker With an Attitude Annoy At Your Own Risk Car Vinyl Decal Sticker
            )
            [22] => 
            [23] => 
            [24] => Array (
                [0] => 1
                [1] => 1
            ) 
            [25] => Array (
                [0] => 1.95
                [1] => 1.95
            ) 
            [26] => £0.00
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £3.90
            [31] => No
            [32] => PayPal
            [33] => 30-Jan-20
            [34] => 30-Jan-20
            [35] => 
            [36] => 
            [37] => 
            [38] => 31-Jan-20
            [39] => 
            [40] => 
            [41] => 
            [42] => 5LD0123456789U
            [43] => Royal Mail 1st Class
            [44] => 
            [45] => 
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

    [3] => Array
        (
            [0] => 15305
            [1] => 25-04445-36722
            [2] => pod69
            [3] => mart badger
            [4] => martsemailddr34@gmail.com
            [5] => 
            [6] => Via Riccione N. 35/30
            [7] => 
            [8] => Sa Tiacca Quartu S. Elena
            [9] => CA
            [10] => 09445
            [11] => Italy
            [12] => Badger Mart
            [13] => +39 987 654 3211
            [14] => Via Riccione N. 35/30
            [15] => 
            [16] => Sa Tiacca Quartu S. Elena
            [17] => CA
            [18] => 09445
            [19] => Italy
            [20] => 302667176336
            [21] => 2x Funny Car & Van or Camper WV Eyelash Vinyl Sticker Decal, Signs - Any Colour!
            [22] => 
            [23] => No
            [24] => 2
            [25] => £1.99
            [26] => £3.14
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £7.12
            [31] => No
            [32] => PayPal
            [33] => 23-Jan-20
            [34] => 23-Jan-20
            [35] => 24-Jan-20
            [36] => 
            [37] => 
            [38] => 24-Jan-20
            [39] => Yes
            [40] => 
            [41] => 
            [42] => 25C157351T6888860U
            [43] => Royal Mail International Standard
            [44] => 
            [45] => 1709118816020
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

    [4] => Array
        (
            [0] => 15306
            [1] => 20-04482-41274
            [2] => wideboiy38887
            [3] => Paul Lastname
            [4] => wideboiysemail@hotmail.co.uk
            [5] => Yellow please
            [6] => 10
            [7] => Broomstick Lane
            [8] => Okehampton
            [9] => Devon
            [10] => EX19 2FT
            [11] => United Kingdom
            [12] => Paul Lastname
            [13] => +44 7866 401983
            [14] => 105
            [15] => Broomstick Lane
            [16] => Okehampton
            [17] => Devon
            [18] => EX19 2FT
            [19] => United Kingdom
            [20] => 302755568952
            [21] => Junglist Soldier Car Window Laptop Wall Gift Drum Bass dnb Jungle Vinyl Sticker
            [22] => 
            [23] => No
            [24] => 1
            [25] => £1.99
            [26] => £0.00
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £1.99
            [31] => No
            [32] => PayPal
            [33] => 01-Feb-20
            [34] => 01-Feb-20
            [35] => 03-Feb-20
            [36] => 
            [37] => 
            [38] => 
            [39] => No
            [40] => 
            [41] => 
            [42] => 7SD68673EE789782X
            [43] => Royal Mail 1st Class
            [44] => 
            [45] => 1711667179020
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

    <!-And so on.....>
<?php
    function readCSV($csvFile)
    {
        $line_of_text = [];
        $file_handle = fopen($csvFile, 'r');
        while (!feof($file_handle)) {
            $tmp = fgetcsv($file_handle, 1024);

            if (isset($line_of_text[$tmp[0]])) {
                foreach ($tmp as $k => $v) {

                    if (array_key_exists($k, $line_of_text[$tmp[0]])) {
                        if (!is_array($line_of_text[$tmp[0]][$k])) {
                            $kVal = $line_of_text[$tmp[0]][$k];

                            $line_of_text[$tmp[0]][$k] = [];
                            $line_of_text[$tmp[0]][$k][] = $kVal;
                        }

                        $line_of_text[$tmp[0]][$k][] = $v;
                        $line_of_text[$tmp[0]][$k] = array_unique($line_of_text[$tmp[0]][$k]);
                        $line_of_text[$tmp[0]][$k] = array_filter($line_of_text[$tmp[0]][$k]);

                        if (count($line_of_text[$tmp[0]][$k]) == 1) {
                            $line_of_text[$tmp[0]][$k] = array_values($line_of_text[$tmp[0]][$k]);
                            $line_of_text[$tmp[0]][$k] = $line_of_text[$tmp[0]][$k][0];
                        }

                        if (empty($line_of_text[$tmp[0]][$k])) {
                            $line_of_text[$tmp[0]][$k] = null;
                        }

                    } else {
                        $line_of_text[$tmp[0]][$k] = null;
                    }
                }
                $line_of_text[$tmp[0]][0] = $tmp[0];

            } else {
                $line_of_text[$tmp[0]] = $tmp;
            }

        }

        fclose($file_handle);
        return array_filter(array_values($line_of_text));
    }

    // Set path to CSV file
    $csvFile = 'test.csv';
    $csv = readCSV($csvFile);

    echo "<pre>";
    print_r($csv);

?>
Array
(
    [0] => Array
        (
            [0] => 15304
            [1] => 15-04478-27247
            [2] => ersmith0
            [3] => eric smith
            [4] => myemail@gmail.com
            [5] => 
            [6] => 2 Any Close
            [7] => 
            [8] => Manchester
            [9] => Greater Manchester
            [10] => M1 5BB
            [11] => United Kingdom
            [12] => eric smith
            [13] => +44 7719 123456
            [14] => 27 Any Close
            [15] => 
            [16] => Manchester
            [17] => Greater Manchester
            [18] => M1 5BB
            [19] => United Kingdom
            [20] => Array
                (
                    [0] => 302804801330
                    [1] => 302804815489
                )

            [21] => Array
                (
                    [0] => CAUTION DRIVEN BY A BIKER  - Fun Vinyl Decal Sticker 4x4/Car/Lorry/Van/Camper
                    [1] => Warning Biker With an Attitude Annoy At Your Own Risk Car Vinyl Decal Sticker
                )

            [22] => 
            [23] => No
            [24] => Array
                (
                    [0] => 2
                    [1] => 1
                )

            [25] => Array
                (
                    [0] => £3.90
                    [1] => £1.95
                )

            [26] => £0.00
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £3.90
            [31] => No
            [32] => PayPal
            [33] => 30-Jan-20
            [34] => 30-Jan-20
            [35] => 
            [36] => 
            [37] => 
            [38] => 31-Jan-20
            [39] => No
            [40] => 
            [41] => 
            [42] => 5LD0123456789U
            [43] => Royal Mail 1st Class
            [44] => 
            [45] => Array
                (
                    [0] => 1711351782020
                    [1] => 1711351781020
                )

            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

    [1] => Array
        (
            [0] => 15305
            [1] => 25-04445-36722
            [2] => pod69
            [3] => mart badger
            [4] => martsemailddr34@gmail.com
            [5] => 
            [6] => Via Riccione N. 35/30
            [7] => 
            [8] => Sa Tiacca Quartu S. Elena
            [9] => CA
            [10] => 09445
            [11] => Italy
            [12] => Badger Mart
            [13] => +39 987 654 3211
            [14] => Via Riccione N. 35/30
            [15] => 
            [16] => Sa Tiacca Quartu S. Elena
            [17] => CA
            [18] => 09445
            [19] => Italy
            [20] => 302667176336
            [21] => 2x Funny Car & Van or Camper WV Eyelash Vinyl Sticker Decal, Signs - Any Colour!
            [22] => 
            [23] => No
            [24] => 2
            [25] => £1.99
            [26] => £3.14
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £7.12
            [31] => No
            [32] => PayPal
            [33] => 23-Jan-20
            [34] => 23-Jan-20
            [35] => 24-Jan-20
            [36] => 
            [37] => 
            [38] => 24-Jan-20
            [39] => Yes
            [40] => 
            [41] => 
            [42] => 25C157351T6888860U
            [43] => Royal Mail International Standard
            [44] => 
            [45] => 1709118816020
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

    [2] => Array
        (
            [0] => 15306
            [1] => 20-04482-41274
            [2] => wideboiy38887
            [3] => Paul Lastname
            [4] => wideboiysemail@hotmail.co.uk
            [5] => Yellow please
            [6] => 10
            [7] => Broomstick Lane
            [8] => Okehampton
            [9] => Devon
            [10] => EX19 2FT
            [11] => United Kingdom
            [12] => Paul Lastname
            [13] => +44 7866 401983
            [14] => 105
            [15] => Broomstick Lane
            [16] => Okehampton
            [17] => Devon
            [18] => EX19 2FT
            [19] => United Kingdom
            [20] => 302755568952
            [21] => Junglist Soldier Car Window Laptop Wall Gift Drum Bass dnb Jungle Vinyl Sticker
            [22] => 
            [23] => No
            [24] => 1
            [25] => £1.99
            [26] => £0.00
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £1.99
            [31] => No
            [32] => PayPal
            [33] => 01-Feb-20
            [34] => 01-Feb-20
            [35] => 03-Feb-20
            [36] => 
            [37] => 
            [38] => 
            [39] => No
            [40] => 
            [41] => 
            [42] => 7SD68673EE789782X
            [43] => Royal Mail 1st Class
            [44] => 
            [45] => 1711667179020
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

)
$arr = [];
//$csv is your array
foreach($csv as $key => $value){
  $arr[$value[0]][] = $value;  
}
print_r($arr);
$arr = [];
//$csv is your array
foreach($csv as $key => $value){
  if(!array_key_exists($value[0],$arr)){
    $arr[$value[0]] = [];
  }
  $arr[$value[0]] = array_merge($arr[$value[0]],$value);  
}
print_r($arr);
$original = [0] => [
  [0] => 'id0',
  [1] => 'name 0',
  [2] => 'street 0'
],
[1] => [
  [0] => 'id0',
  [1] => 'name 1',
  [2] => 
],
[2] => [
  [0] => 'id0',
  [1] =>,
  [2] => 'street 2'
]
$new = [0] => [
  [0] => 'id0',
  [1] => [
    [0] => 'name 0',
    [1] => 'name 1'
  ],
  [2] => [
    [0] => 'street 0',
    [1] => 'street 2'
  ]
]
function readCsv($csvFileName) {
    $file_handle = fopen($csvFile, 'r');
    $records = [];
    fgetcsv($file_handle);
    while (!feof($file_handle) ) {
        $line = fgetcsv($file_handle, 1024);
        $id = $line[0];
        if (!$records[$id]) $records[$id] = [];
        $records[$id][] = $line;
    }
    fclose($file_handle);
    return $records;
}

function printCsvColumn($rowName, $sales) {
    $uniqueSales = array_unique($sales);
    $uniqueNotNullSales = array_filter($uniqueSales, 'strlen');
    foreach ($uniqueNotNullSales as $sale) {
        echo $rowName . ': ' . $sale[$rowName];
    }
}

function printCsv($records) {
    foreach ($records as $sales) {
        foreach ($sales[0] as $rowName=>$rowValue) {
            printCsvColumn($rowName, $sales);
        }
    }
}