I have the following string:
$string = "[{"006":"BASIC"}, {"007":"ADV"}]";
I need a final array in the form of:
Array(
"006" => BASIC,
"007" => ADV
)
I did it the dirty way as follows:
$string = ltrim($string, "[");
$string = rtrim($string, "]");
$string = explode(",", $string);
$arr1 = json_decode($string[0], true);
$arr2 = json_decode($string[1], true);
$arrFinal = array_merge($arr1, $arr2); //Final Array
Can this be done in a more optimized way?
Also, the original $string can have multiple comma separated segments, and not just two, like below->
$string = "[{"006":"BASIC"}, {"007":"ADV"}, {"008":"ADV"}, {"009":"SUPER"}]";