PHP array_flip of removes special functions that duplicate array elements

  • 2020-03-31 20:43:37
  • OfStack

instructions
Array array_flip (array trans)
Array_flip () returns an inverted array, such that the key name in trans becomes the value, and the value in trans becomes the key name.
Note that the value in trans needs to be valid as a key name, such as integer or string. A warning is issued if the value is of the wrong type, and the key/value pair in question will not be reversed.
If the same value appears multiple times, the last keyname will be its value, and all others are lost.
Array_flip () returns FALSE on failure.
Example:
 
  $hills=array("first"=>"data1 " ,"second"=>"data2 " ,"third"=>"data1 " ); 
  $hills=array_flip($hills); //Restore the keys
  $hills1=array_flip(array_flip($hills));//Remove duplicate
  display $hills1 

The result is:

Data2 data1 two data.

Related articles: