开关关联数组两个项目

问题描述:

例如:

$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

$arr = array(
  '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?

感谢

有没有简单的方法,只是一个循环或一个新的数组定义。

There is no easy way, just a loop or a new array definition.