php - Need to explode and string and make it as key value pairs -


i have data

[0] => 1#*#1-1 

my requirement explode #*# , have make generated array elements key value pairs

example

$data = explode("#*#",'1#*#1-1'); 

$data[0] =1; $data[1] = 1-1; requirement make dynamic associative array

array($data[1] => $data[0]) 

<? $str = '1#*#1-1      3#*#1-2      5#*#1-3      7#*#1-4      9#*#1-5      11#*#1-6      13#*#1-7      15#*#1-8      17#*#1-9      19#*#1-10      2#*#2-1      4#*#2-2      6#*#2-3      8#*#2-4      10#*#2-5      12#*#2-6      14#*#2-7      16#*#2-8      18#*#2-9';  $ex = array_map('trim',explode("\n",$str)); $out = array(); foreach($ex $e){     $ex2 = explode('#*#',$e);     $out[$ex2[1]] = $ex2[0]; }  print_r($out);  array (     [1-1] => 1     [1-2] => 3     [1-3] => 5     [1-4] => 7     [1-5] => 9     [1-6] => 11     [1-7] => 13     [1-8] => 15     [1-9] => 17     [1-10] => 19     [2-1] => 2     [2-2] => 4     [2-3] => 6     [2-4] => 8     [2-5] => 10     [2-6] => 12     [2-7] => 14     [2-8] => 16     [2-9] => 18 ) ?> 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -