This question already has an answer here:
- Swap array values with php 11 answers
Here is an array:
$array = (0 => "pear", 1 => "apple", 2 => "orange", 3 => "kiwi");
What is the best way to reorder the array to become:
$array = (0 => "pear", 1 => "kiwi", 2 => "orange", 3 => "apple");
Edit:
Please note I am not looking for an alphabetical sort. I am looking to switch the order of two items within an array. My initial thought was to pop out the key=>value pair that I want to change, then reinsert it. But I want to know if there is a better way.
</div>