I have two array one array is fetched from database and second is the array of user id's mean i want to sort the fetched user array based on second given array. I want those users on the top of array who exists in second array in and those user whose not exists in second input array will also come after the sorted users in php
$sortArr = array(14,25);
$dbArr = array(7,5,100,25,110,78,14);
sort_tag_able_users($sortArr,$dbArr);
function sort_tag_able_users($inputs, $db_inputs) {
foreach ($db_inputs as $url_response) {
$key = array_search($url_response, $inputs);
$result[$key] = $url_response;
}
ksort($result);
return $result;
}
echo "Returned Reusult";
Array
(
[0] => 14
[1] => 25
)
echo "Required Reusult";
Array
(
[0] => 14
[1] => 25
[2] => 7
[3] => 5
[4] => 100
[5] => 110
[6] => 78
)
above function that I have it only return the matched users and remaning users removed from the db array. Help to solve this issue.