Home >Backend Development >PHP Tutorial >php-Arrays function-array_flip-exchange keys and values ​​in array_PHP tutorial

php-Arrays function-array_flip-exchange keys and values ​​in array_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:51:131125browse

array_flip() function exchanges the keys and values ​​in the array

【Function】
This function will return a reversed array,
That is, the value of the original array becomes the key value of the new array, and the key value of the original array becomes the value of the new array
If there are the same values ​​in the array, only the last one with the same value will be reversed to the new array
【Scope of use】
​​​​​ php4, php5.
【Use】
array array_flip( array trans )
          trans/required/array to be reversed
【Example】
[php]
$array1 = array( "blue" => 6, "red" => 2, "green" => 3, "purple" => 4 );
$array2 = array( "blue" => 6, "red" => 4, "green" => 6, "purple" => 4 );
$array3 = array( "blue" => 6, "red" => 4, "green" => 6, "purple" => '' );

print_r( array_flip( $array1 ) );
print_r( array_flip( $array2 ) );
print_r( array_flip( $array3 ) );

/*
Array
(
[6] => blue
[2] => red
[3] => green
[4] => purple
)
Array
(
[6] => green
[4] => purple
)
Array
(
[6] => green
[4] => red
[] => purple
)
*/


Excerpted from zuodefeng’s notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478206.htmlTechArticlearray_flip() function exchanges the keys and values ​​in the array [Function] This function will return a reversed array , that is, the value of the original array becomes the key value of the new array, and the key value of the original array becomes the new...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn