php中array_flip数组翻转

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

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

Return Values ¶

Returns the flipped array on success and NULL on failure.

Examples ¶

Example #1 array_flip() example

<?php
$trans = array_flip($trans);
$original = strtr($str, $trans);
?>

Example #2 array_flip() example : collision

<?php
$trans = array("a" => 1, "b" => 1, "c" => 2);
$trans = array_flip($trans);
print_r($trans);
?>

now $trans is:

Array
(
    [1] => b
    [2] => c
)
原文地址:https://www.cnblogs.com/wangkongming/p/3811903.html