3v4l.org

run code in 300+ PHP versions simultaneously
<?php $profiles = [ [ 'user_id' => 'fcc3d884-fbef-438a-9c86-0ad52c9b1223', 'first_name' => 'Narñia', 'middle_name' => 'Ñ', 'last_name' => 'Cruz', 'ext' => '' ], [ 'user_id' => '0d31557d-1e9f-4db3-ac0d-72e1709fe89c', 'first_name' => 'Randy', 'middle_name' => 'O', 'last_name' => 'Rocker', 'ext' => '' ], [ 'user_id' => '0f93f169-cf56-49df-a76b-7596446104c6', 'first_name' => 'Qwerty', 'middle_name' => 'K', 'last_name' => 'Asdfg', 'ext' => '' ], [ 'user_id' => '23b1f4a2-034c-43b4-96b7-3191d78cead1', 'first_name' => 'Johny', 'middle_name' => 'L', 'last_name' => 'Walker', 'ext' => '' ] ]; $encoded = [ [ 'encoder_id' => '0d31557d-1e9f-4db3-ac0d-72e1709fe89c', 'fullname' => 'Randy O. Rocker', 'encoded' => 10, ], [ 'encoder_id' => '23b1f4a2-034c-43b4-96b7-3191d78cead1', 'fullname' => 'John L. Walker', 'encoded' => 20, ] ]; $encodedByEncoderId = array_column($encoded, null, 'encoder_id'); $combined = array_reduce($profiles, static function (array $combined, array $profile) use ($encodedByEncoderId) : array { $combined[] = [ 'id' => $profile['user_id'], 'fullname' => "{$profile['first_name']} {$profile['middle_name']}. {$profile['last_name']}", 'encoded' => $encodedByEncoderId[$profile['user_id']]['encoded'] ?? 0 ]; return $combined; }, []); print_r($combined);
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.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
Array ( [0] => Array ( [id] => fcc3d884-fbef-438a-9c86-0ad52c9b1223 [fullname] => Narñia Ñ. Cruz [encoded] => 0 ) [1] => Array ( [id] => 0d31557d-1e9f-4db3-ac0d-72e1709fe89c [fullname] => Randy O. Rocker [encoded] => 10 ) [2] => Array ( [id] => 0f93f169-cf56-49df-a76b-7596446104c6 [fullname] => Qwerty K. Asdfg [encoded] => 0 ) [3] => Array ( [id] => 23b1f4a2-034c-43b4-96b7-3191d78cead1 [fullname] => Johny L. Walker [encoded] => 20 ) )

preferences:
68.13 ms | 408 KiB | 5 Q