I have an array of countries that I will be using in a select menu:
array(
[0] => " -- Select -- "
[1] => "Afghanistan"
[3] => "Albania"
[4] => "Algeria"
[39] => "Canada"
[47] => "USA"
)
//etc...
I want to copy create copies of the Canada and USA entries and place them at the front of my array. So the array should end up looking like this:
array(
[0] => " -- Select -- "
[47] => "USA"
[39] => "Canada"
[1] => "Afghanistan"
[3] => "Albania"
[4] => "Algeria"
[39] => "Canada"
[47] => "USA"
)
//etc...
The array keys correspond to their ID in the database, so I can't change the keys. How can I achieve this?
Solution
I realized that this is not possible. When you try to set a value in an array with a duplicate key, it overwrites the first key. I came up with a different solution, but have accepted the highest rated answer.