My PHP app will upload a selected csv file into memory. It is then converted into an array using str_getcsv as shown below.
//get file from session variable created in upload.php
$uploadedfile = str_getcsv($_SESSION['uploadedfile'], "\n");
//remove first two rows as these contain headers
unset($uploadedfile[0]);
unset($uploadedfile[1]);
the array currently looks like this:
array(4174) {
[2]=>
string(180) "productID,ProductBarcode,brand,productType,productName"
[3]=>
string(178) "productID,ProductBarcode,brand,productType,productName"
I need to loop through each row and explode the comma separated value into a multidimensional array. So it looks something like this:
array() {
[row2]=>
"productID => 001"
"ProductBarcode=>101010"
"brand=>apple"
"productType=>notebook"
"productName=>Macbook pro"
[row3]=>
"productID => 002"
"ProductBarcode=>20202"
"brand=>apple"
"productType=>desktop"
"productName=>iMac"
}
I believe this question was tring to answer a similar thing but the answer wasn't provided: PHP: Parsing Comma-Separated Values Between Square Brackets into Multi-Dimensional Array