3v4l.org

run code in 300+ PHP versions simultaneously
<?php $profiles = array( array( 'user_id' => 'fcc3d884-fbef-438a-9c86-0ad52c9b1223', 'first_name' => 'Narñia', 'middle_name' => 'Ñ', 'last_name' => 'Cruz', 'ext' => '' ), array( 'user_id' => '0d31557d-1e9f-4db3-ac0d-72e1709fe89c', 'first_name' => 'Randy', 'middle_name' => 'O', 'last_name' => 'Rocker', 'ext' => '' ), array( 'user_id' => '0f93f169-cf56-49df-a76b-7596446104c6', 'first_name' => 'Qwerty', 'middle_name' => 'K', 'last_name' => 'Asdfg', 'ext' => '' ), array( 'user_id' => '23b1f4a2-034c-43b4-96b7-3191d78cead1', 'first_name' => 'Johny', 'middle_name' => 'L', 'last_name' => 'Walker', 'ext' => '' ) ); $encoded = array( array( 'encoder_id' => '0d31557d-1e9f-4db3-ac0d-72e1709fe89c', 'fullname' => 'Randy O. Rocker', 'encoded' => 10, ), array( 'encoder_id' => '23b1f4a2-034c-43b4-96b7-3191d78cead1', 'fullname' => 'John L. Walker', 'encoded' => 20, ) ); $encoded_ids = array_column($encoded, null, 'encoder_id'); $data = array(); foreach ($profiles as $profile) { $user_id = $profile['user_id']; if (isset($encoded_ids[$user_id])) { $data[] = array('id' => $user_id, 'fullname' => $encoded_ids[$user_id]['fullname'], 'encoded' => $encoded_ids[$user_id]['encoded'] ); } else { $data[] = array('id' => $user_id, 'fullname' => "${profile['first_name']} ${profile['middle_name']} ${profile['last_name']}", 'encoded' => 0 ); } } usort($data, function ($a, $b) { return $b['encoded'] - $a['encoded'];}); print_r($data);
Output for 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/FXtsE on line 60 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/FXtsE on line 60 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/FXtsE on line 60 Array ( [0] => Array ( [id] => 23b1f4a2-034c-43b4-96b7-3191d78cead1 [fullname] => John L. Walker [encoded] => 20 ) [1] => Array ( [id] => 0d31557d-1e9f-4db3-ac0d-72e1709fe89c [fullname] => Randy O. Rocker [encoded] => 10 ) [2] => Array ( [id] => fcc3d884-fbef-438a-9c86-0ad52c9b1223 [fullname] => Narñia Ñ Cruz [encoded] => 0 ) [3] => Array ( [id] => 0f93f169-cf56-49df-a76b-7596446104c6 [fullname] => Qwerty K Asdfg [encoded] => 0 ) )
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
Array ( [0] => Array ( [id] => 23b1f4a2-034c-43b4-96b7-3191d78cead1 [fullname] => John L. Walker [encoded] => 20 ) [1] => Array ( [id] => 0d31557d-1e9f-4db3-ac0d-72e1709fe89c [fullname] => Randy O. Rocker [encoded] => 10 ) [2] => Array ( [id] => fcc3d884-fbef-438a-9c86-0ad52c9b1223 [fullname] => Narñia Ñ Cruz [encoded] => 0 ) [3] => Array ( [id] => 0f93f169-cf56-49df-a76b-7596446104c6 [fullname] => Qwerty K Asdfg [encoded] => 0 ) )

preferences:
83.41 ms | 410 KiB | 5 Q