arrays - Explode string in PHP that contain brackets and semicolon -


problem:

i have string looks this:

[1=>2,3,4][5=>6,7,8][9=>10,11,12][13=>14,15][16=>17,18] 

question:

how can string this?

1     2     3     4 5     6     7     8 9     10     11     12 13     14     15 16     17     18 

$str = "[1=>2,3,4][5=>6,7,8][9=>10,11,12][13=>14,15][16=>17,18]"; $str = explode("]", $str); $finalresult = array();  foreach ($str $element) {     if (!empty($element)) {         $element = substr($element, 1);         $element = explode("=>", $element);          // element[0] contains key         $element[1] = explode(",", $element[1]);         $finalresult[$element[0]] = $element[1];     } }  print_r($finalresult); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -