I have just started learning PHP and stuck with the concept of Associative arrays. all of the examples i have seen so far are dealing with csv files. I actually have csv as a string where first row act as keys and all the following rows are values stored in multidimensional array.
the input csv string is like this or I believe this is how a csv string look like:
"fname,lname
a,b
c,d"
the output should be: (consider the the input to be very long not just two lines)
[
["fname"=> "a" , "lname"=>"b"],
["fname"=> "c" , "lname"=>"d"]
]
as i am trying to learn PHP so this is what i have done so far:
<?php
// original string
$OriginalString = "fname,lname,a,b,c,d,e,f";
//get each item
$SplittedString = array(explode(",",$OriginalString));
}
?>
here is a close to solution for this question: PHP CSV to associative array with top row as keys and columns as value arrays
what I have thought to convert csv string to csv file and then use the normal solution already available online. That should do the job but i would like to see what other possible solution could be for this specific output.