3v4l.org

run code in 300+ PHP versions simultaneously
<?php $first_array = Array ( '0' =>Array ( 'id_person' => 194, 'firstname' =>'Jesper', 'lastname' =>'Hansen' , 'pos' => 29, 'position' => 1, 'starter' => 0, 'subs' => 0, 'goal' => 0, 'yellow_card' => null, 'red_card' => null, ) , '1' =>Array ( 'id_person' => 195, 'firstname' =>'Mikkel', 'lastname' =>'Andersen' , 'pos' => 1, 'position' => 1, 'starter' => 1, 'subs' => 0, 'goal' => 0, 'yellow_card' => null, 'red_card' => null, ) , '2' =>Array ( 'id_person' => 197, 'firstname' =>'Alexander', 'lastname' =>'Scholz' , 'pos' => 6, 'position' => 2, 'starter' => 1, 'subs' => 0, 'goal' => 0, 'yellow_card' => null, 'red_card' => null, ) , '3' =>Array ( 'id_person' => 198, 'firstname' =>'Erik', 'lastname' =>'Sviatchenko' , 'pos' => 10, 'position' => 2, 'starter' => 1, 'subs' => 0, 'goal' => 0, 'yellow_card' => null, 'red_card' => null, ) , '4' =>Array ( 'id_person' => 199, 'firstname' =>'Kian', 'lastname' =>'Hansen' , 'pos' => 14, 'position' => 2, 'starter' => 1, 'subs' => 0, 'goal' => null, 'yellow_card' => null, 'red_card' => null, ) , '5' =>Array ( 'id_person' => 204, 'firstname' =>'Manjrekar', 'lastname' =>'James' , 'pos' => 30, 'position' => 2, 'starter' => 0, 'subs' => 0, 'goal' => 0, 'yellow_card' => null, 'red_card' => null, ) , '6' =>Array ( 'id_person' => 236, 'firstname' =>'Sebastian', 'lastname' =>'Buch' , 'pos' => 14, 'position' => 14, 'starter' => 0, 'subs' => 0, 'goal' => 0, 'yellow_card' => null, 'red_card' => null, ) , '7' =>Array ( 'id_person' => 209, 'firstname' =>'Joel', 'lastname' =>'Andersson', 'pos' => 18, 'position' => 3, 'starter' => 1, 'subs' => 0, 'goal' => 0, 'yellow_card' => null, 'red_card' => null, ) ); $second_array = Array ( '0' => Array ( 'id_person' => 195, 'position' => 1, 'first' => 'Mikkel', 'last' => 'Andersen' , 'id_club' => 2, 'type' => 2, 'captain' => 0, 'pos' => 1, 'subsmin_in' => null, 'subsmin_out' => null, 'starter' => 1, 'subs' => 0, 'goal' => 0, 'yellow_card' => null, 'red_card' => null, ) , '1' => Array ( 'id_person' => 236, 'position' => 14, 'first' => 'Sebastian', 'last' => 'Buch' , 'id_club' => 2, 'type' => 2, 'captain' => 0, 'pos' => 14, 'subsmin_in' => null, 'subsmin_out' => null, 'starter' => 0, 'subs' => 0, 'goal' => 0, 'yellow_card' => null, 'red_card' => null, ) , '2' => Array ( 'id_person' => 209, 'position' => 3, 'first' => 'Joel', 'last' => 'Andersson' , 'id_club' => 2, 'type' => 2, 'captain' => 0, 'pos' => 18, 'subsmin_in' => null, 'subsmin_out' => null, 'starter' => 1, 'subs' => 0, 'goal' => 0, 'yellow_card' => null, 'red_card' => null, ) ); foreach($second_array as $k=>$v){ $id_person = $v['id_person']; $key = array_search($id_person, array_column($first_array, 'id_person')); if($key){ $second_array[$k]['starter'] = $first_array[$key]['starter']; $second_array[$k]['subs'] = $first_array[$key]['subs']; $second_array[$k]['yellow_card'] = $first_array[$key]['yellow_card']; $second_array[$k]['red_card'] = $first_array[$key]['red_card']; } } print_r($second_array); ?>
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Array ( [0] => Array ( [id_person] => 195 [position] => 1 [first] => Mikkel [last] => Andersen [id_club] => 2 [type] => 2 [captain] => 0 [pos] => 1 [subsmin_in] => [subsmin_out] => [starter] => 1 [subs] => 0 [goal] => 0 [yellow_card] => [red_card] => ) [1] => Array ( [id_person] => 236 [position] => 14 [first] => Sebastian [last] => Buch [id_club] => 2 [type] => 2 [captain] => 0 [pos] => 14 [subsmin_in] => [subsmin_out] => [starter] => 0 [subs] => 0 [goal] => 0 [yellow_card] => [red_card] => ) [2] => Array ( [id_person] => 209 [position] => 3 [first] => Joel [last] => Andersson [id_club] => 2 [type] => 2 [captain] => 0 [pos] => 18 [subsmin_in] => [subsmin_out] => [starter] => 1 [subs] => 0 [goal] => 0 [yellow_card] => [red_card] => ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Array ( [0] => Array ( [id_person] => 195 [position] => 1 [first] => Mikkel [last] => Andersen [id_club] => 2 [type] => 2 [captain] => 0 [pos] => 1 [subsmin_in] => [subsmin_out] => [starter] => 1 [subs] => 0 [goal] => 0 [yellow_card] => [red_card] => ) [1] => Array ( [id_person] => 236 [position] => 14 [first] => Sebastian [last] => Buch [id_club] => 2 [type] => 2 [captain] => 0 [pos] => 14 [subsmin_in] => [subsmin_out] => [starter] => 0 [subs] => 0 [goal] => 0 [yellow_card] => [red_card] => ) [2] => Array ( [id_person] => 209 [position] => 3 [first] => Joel [last] => Andersson [id_club] => 2 [type] => 2 [captain] => 0 [pos] => 18 [subsmin_in] => [subsmin_out] => [starter] => 1 [subs] => 0 [goal] => 0 [yellow_card] => [red_card] => ) )
Output for 5.3.0
Fatal error: Call to undefined function array_column() in /in/FeanU on line 180
Process exited with code 255.

preferences:
130.19 ms | 401 KiB | 182 Q