Flip the keys and values of an array to make a new array. This new one will have the old values as the keys and the old keys as the corresponding values. If there are duplicate new keys, only the last one will keep its value.

If the value can not be used as a key (it must be a string or integer) then that pair will not be flipped and a warning is given.

$arr = array('apple',
             'banana',
             'carrot',
             'a' => 'zebra',
             'b' => 'yak');
 
$new = array_flip($arr);
/*
array (
  'apple' => 0,
  'banana' => 1,
  'carrot' => 2,
  'zebra' => 'a',
  'yak' => 'b'
)
*/
 
$arr = array('apple',
             'banana',
             'carrot',
             'a' => 'zebra',
             'b' => 'banana');
 
$new = array_flip($arr);
/*
array (
  'apple' => 0,
  'banana' => 'b',
  'carrot' => 2,
  'zebra' => 'a'
)
*/
 
$arr = array('apple',
             null,
             'carrot',
             'a' => 'zebra',
             'b' => 'yak');
 
$new = array_flip($arr);
/*
array (
  'apple' => 0,
  'carrot' => 2,
  'zebra' => 'a',
  'yak' => 'b'
)
*/
// Also, a warning is given:
// "Can only flip STRING and INTEGER values!"