- json_decode: documentation ( source)
- preg_match: documentation ( source)
- print_r: documentation ( source)
- preg_replace: documentation ( source)
<?php
$json = '{"Template[URL]":"asdasdda.com","Template[UPC]":"548454854631… Example","FieldHow to Answer":"20"}';
$output = json_decode($json);
print_r($output);
$newArray = array();
$array = $output;
foreach ($array as $key=>$value) {
preg_match("/\[(.+)\]/",$key,$match);
$newKey = preg_replace("/\[.+\]/","",$key);
$newArray[$newKey][$match[1]] = $value;
}
print_r($newArray);