PHP array change array structure -


i have array in following form,

array (     [foo] => array         (             [3] => hello             [1] => world         )     [bar] => array         (             [3] => other stuff             [1] => more stuff          )     [baz] => array         (             [3] => value         ) ) 

how have on following form:

array (     [3] => array         (                 [foo] => hello             [bar] => other stuff                        [baz] => value         )     [1] => array         (             [foo] => world             [bar] => more stuff           ) ) 

thanks

$array;  //<--- assuming array starting  $new_array = array();  //<--- new array you're building  foreach($array $i=>$element) {     foreach($element $j=>$sub_element)     {         $new_array[$j][$i] = $sub_element; //we inverting indexes     } } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -