Switch two items in associative array PHP
- by user280381
Example:
$arr = array('apple'='sweet','grapefruit'='bitter','pear'='tasty','banana'='yellow');
I want to switch the positions of grapefruit and pear, so the array will become
'apple'='sweet','pear'='tasty','grapefruit'='bitter','banana'='yellow')
I know the keys and values of the elements I want to switch, is there an easy way to do this? Or will it require a loop + creating a new array?
Thanks