I am receiving csv data as separate strings which I am trying to convert into nested arrays, and then json.
The strings I am receiving are like this, where the last element is the value.
$str1 = "name,firstname,Bob";
$str2 = "name,lastname,Dylan";
Here I need to convert the strings into nested arrays which would be equivalent to the arrays below. This is the bit I am struggling with.
$arr1 = ["name" => ["firstname" => "Bob"]];
$arr2 = ["name" => ["lastname" => "Dylan"]];
I can then use a array_merge_recursive to combine them
$merged = array_merge_recursive($arr1, $arr2);
After that I can convert the merged array into json