PHP: How to copy elements from an associative array and place them at the beginning of the array?
- by Andrew
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?