3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array( 'type1' => array( 'id' => 'w12', 'name' => 'John Doe', 'email' => 'john@example.com', 'fname' => 'john', 'phone' => '111', 'age' => '22' ), 'type2' => array( 'id' => 'w13', 'name' => 'Jane Doe', 'email' => 'jane@example.com', 'age' => '22', 'phone' => '111', 'fname' => 'dsd' ), ); $order = [ 'id' => null, 'name' => null, 'fname' => null, 'phone' => null, 'age' => null, 'email' => null ]; $ordered = array_map(function($row) use ($order) { return array_merge($order, $row); }, $array); var_dump($ordered);
Output for 7.3.0rc3
array(2) { ["type1"]=> array(6) { ["id"]=> string(3) "w12" ["name"]=> string(8) "John Doe" ["fname"]=> string(4) "john" ["phone"]=> string(3) "111" ["age"]=> string(2) "22" ["email"]=> string(16) "john@example.com" } ["type2"]=> array(6) { ["id"]=> string(3) "w13" ["name"]=> string(8) "Jane Doe" ["fname"]=> string(3) "dsd" ["phone"]=> string(3) "111" ["age"]=> string(2) "22" ["email"]=> string(16) "jane@example.com" } }