I have a csv like this.
I have created a CLI script, which will read the CSV and It will create an array based on account id, address id and SKU.
I will execute the script like this
php csvimport.php 10 /var/www/test/testcsv.csv
In the above code, 10 is the limit of the script which will take the first 10 then it will create an array, then it will look for next 10 and it will create another array. Here I need to handle a condition that the first row value of the batch should match the next 9 rows. If there is no match after the first row then will create that row as separate array.
I need the expected output. Every time it will take the limit and compare the rows based on the first row of the limit.
array[A1][ad1] => SKU1,SKU2,SKU3,SKU4,SKU5,SKU25,SKU26
array[A1][ad12] => SKU1
array[A1][ad2] => SKU3,SKU4,SKU5,SKU6,SKU7,SKU8
array[A2][ad2-1] => SKU13,SKU14,SKU15,SKU16,SKU17,SKU18
$file = '/var/www/html/var/csv/cv1.csv'; $arr=array(); $row = 1; $i = 1; $limit = 10; if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); $row++; for ($c = 0; $c < $num; $c++) { $arr[$row][$data[0]][$data[1]]= $data[$c]; if ($i++ == $limit) break; } } fclose($handle); } echo "<pre>"; print_r($arr); exit;