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);

preferences:
48.44 ms | 406 KiB | 5 Q