PHP array function sequence array_flip() swaps array key names and values_PHP tutorial

WBOY
Release: 2016-07-21 15:22:40
Original
1446 people have browsed it

array_flip() Definition and usage

array_flip() function will swap the key name of the array with its corresponding value, that is, the key name becomes the value, and the value becomes the key name.

array_flip() function returns a reversed array. If the same value appears multiple times, the last key name will be used as its value and all other key names will be lost.

If the data type of the value in the original array is not string or integer, the function will report an error.

Syntax
array_flip(array) Parameter Description
array Required. Specifies the input array.

Example

Copy code The code is as follows:

$a=array (0=>"Dog",1=>"Cat",2=>"Horse");print_r(array_flip($a));
?>

Output:

Array ( [Dog] => 0 [Cat] => 1 [Horse] => 2 )

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324616.htmlTechArticlearray_flip() Definition and Usage The array_flip() function will swap the key name of the array with its corresponding value, that is, the key name Becomes a value, and the value becomes a key name. The array_flip() function returns a reversed...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!