I have two arrays, the first one is the sorted version (sorted by the user) of the second one, but the second one can be shorter or longer than the first one. For example:
$books_sorted = array(
0 => array(
"title" => "In Search of Lost Time"
),
1 => array(
"title" => "Don Quixote"
),
2 => array(
"title" => "The Great Gatsby"
)
);
$books_available = array(
0 => array(
"title" => "Moby Dick"
),
1 => array(
"title" => "In Search of Lost Time"
),
2 => array(
"title" => "The Great Gatsby"
),
3 => array(
"title" => "War and Peace"
)
);
I need a result array that respects the order set by the user, but removes the missing books from the second array and adds them to the end of all the new books from the second array. Ex.
// "Don Quixote" is not available anymore -> needs to be removed
// "War and Peace" and "Moby Dick" are available -> need to be added both at the end
$books_third_array = array(
0 => array(
"title" => "In Search of Lost Time"
),
1 => array(
"title" => "The Great Gatsby"
),
2 => array(
"title" => "Moby Dick"
),
3 => array(
"title" => "War and Peace"
)
);
I only put the "title" key because there are others, but I don't think they're useful to this example.