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
)

相关文章:

  • 2021-10-31
  • 2022-02-05
  • 2021-05-31
  • 2022-12-23
  • 2021-11-27
猜你喜欢
  • 2021-09-24
  • 2022-02-02
  • 2022-12-23
  • 2022-02-03
  • 2021-06-12
  • 2022-12-23
  • 2022-01-08
相关资源
相似解决方案