I have a CSV file, which I'm parsing into an associative array, which I need to save in the DB. The issue is that some of my CSV columns contain other CSV values, which I will need to insert separately into the DB. Examples talk better, so here goes:
ID, Col1, Col2
1, "Example 1.1.1,Example 1.1.2", Example 1.2
2, Example 2.1, "Example 2.2.1, Example 2.2.2"
As you can see, for row 1, there are 2 values in the first column, and for row 2, there are 2 values in the 2nd column.
I somehow need to get these to expand to 4 separate array items, which look like:
array(
[0] => array( "ID" => 1, "Col1" => "Example 1.1.1", "Col2" => "Example 1.2" ),
[1] => array( "ID" => 1, "Col1" => "Example 1.1.2", "Col2" => "Example 1.2" ),
[2] => array( "ID" => 2, "Col1" => "Example 2.1", "Col2" => "Example 2.2.1" )
[3] => array( "ID" => 2, "Col1" => "Example 2.1", "Col2" => "Example 2.2.2" )
)
Is there a function in PHP that does that, or do I have to loop through the entire thing?