php - explode string to a multi array with 2 delimiter -


i have kind of sting variable in php:

 $hccrol = ga#cor,op#cor,for#tb,ga#lts,for#mod,ga#pmai,ldr#lid,hcc#lad,hn#lad,op#lad,ga#lad,ga#wm,op#wm,hn#wm,op#vz,hn#vz,ga#vzai 

i want convert multi array somthing this:

array ( [ga] => array ( [1] => cor                          [2] => lts                          [3] => lad                          [4] => wm                          [5] => vzai                        )         [for] => array( [1] => tb                         [2] => mod                       )         [op] => array(  [1] => cor                         [2] => wm                         [3] => vz                       ) ) 

so # determines in witch primary array value must come

cbroe gave steps traditional way, fun because bored:

parse_str(str_replace(array('#',','), array('[]=','&'), $hccrol ), $result); print_r($result); 

php >= 5.4.0:

parse_str(str_replace(['#',','], ['[]=','&'], $hccrol ), $result); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -