3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $users = Array( Array( 'userId' => 'user1', 'name' => 'Suman Mandal', 'age' => 20, ), Array( 'userId' => 'user2', 'name' => 'Amit Halder', 'age' => 30, ), Array( 'userId' => 'user3', 'name' => 'Asif Rahman', 'age' => 25, ), Array( 'userId' => 'user4', 'name' => 'Gopal Ghosh', 'age' => 21, ) ); $marks = Array( Array( 'userId' => 'user1', 'marks'=>80, ), Array( 'userId' => 'user3', 'marks'=>90, ) ); $users = array_column($users, null, 'userId'); $marks = array_column($marks, null, 'userId'); $marks_sheet = array_replace($marks, $users); var_dump($marks_sheet);
Output for 7.3.0rc3
array(4) { ["user1"]=> array(3) { ["userId"]=> string(5) "user1" ["name"]=> string(12) "Suman Mandal" ["age"]=> int(20) } ["user3"]=> array(3) { ["userId"]=> string(5) "user3" ["name"]=> string(11) "Asif Rahman" ["age"]=> int(25) } ["user2"]=> array(3) { ["userId"]=> string(5) "user2" ["name"]=> string(11) "Amit Halder" ["age"]=> int(30) } ["user4"]=> array(3) { ["userId"]=> string(5) "user4" ["name"]=> string(11) "Gopal Ghosh" ["age"]=> int(21) } }