$original_ids = array(1, 2, 3, 4); //<--- Original values without sorted. $sorted_ids = array(4, 1, 3); //<--- Fixed values (sort by this) $result_ids = array(); //<--- The result array after sorted
I just want to reinstall the associated array and sort it by $sorted_ids (if you understand)
$ result_ids should be ... array(4, 1, 3, 2) ( 2 is not in the $ original_ids array, so put it in last )
I got attached to a code like ...:
foreach ($sorted_ids as &$id) { if (in_array($id , $original_ids)) { $result_ids[] = $id; } else { } }
But I have no idea how to push arrays without matching for the last $ result_ids array.
Comment if you do not understand.
source share