How to Convert a Flattened Array to Multidimensional Array in PHP -


i trying convert key values of array multi-dimensional array. key values multidimensional, text. have tried exploding the string , creating new array, feel there must simpler that.

example below:

array ( [template[url]] => http://www.asdasdda.com [template[upc]] => 5484548546314 [field[value]] =>  test example [field[answer]] => 20 ) 

all appricated. :)

update: exact output of data before run json_decode on data.

{"template[url]":"http://www.asdasdda.com","template[upc]":"5484548546314","field[value]":"test example","field[answer]":"20"} 

fiddled around bit, , think got it. don't think there simpler way:

foreach ($array $key=>$value) {     preg_match("/\[(.+)\]/",$key,$match);     $newkey = preg_replace("/\[.+\]/","",$key);     $newarray[$newkey][$match[1]] = $value; } 

where print_r() of $newarray follows:

array (      [template] => array (          [url] => http://www.asdasdda.com          [upc] => 5484548546314          )      [field] => array (          [value] => test example          [answer] => 20          )      ) 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -