php数组函数序列之array_flip() 将数组键名与值对调_PHP

WBOY
Release: 2016-06-01 12:13:47
Original
824 people have browsed it

array_flip() 定义和用法

array_flip() 函数将使数组的键名与其相应值调换,即键名变成了值,而值变成了键名。

array_flip() 函数返回一个反转后的数组,如果同一值出现了多次,则最后一个键名将作为它的值,所有其他的键名都将丢失。

如果原数组中的值的数据类型不是字符串或整数,函数将报错。

语法
array_flip(array)参数 描述
array 必需。规定输入的数组。

例子
复制代码代码如下:
$a=array(0=>"Dog",1=>"Cat",2=>"Horse");print_r(array_flip($a));
?>

输出:

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

Related labels:
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
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!