PHP Array_flip () method

Source: Internet
Author: User

array_flip- exchanging keys and values in an array

array array_flip ( array $trans )

Array_flip () returns a reversed array, such as trans the key name in the value, and the trans value in the key name.

Note trans the values in need to be able to be valid as a key name, such as an integer or string. If the value is of the wrong type, a warning will be issued and the problematic key/value pair will not be reversed .

If the same value occurs more than once, the last key will be its value, and all the others are lost.

Parameters

trans

An array of key/value pairs to exchange.

return value

On success, returns an array after the interchange if it fails NULL .

Example

Example #1 array_flip () example

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

Example #2 Array_flip () Example: conflict

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

Now $trans it is:

Array (    [1] = b    [2] = c)

PHP Array_flip () method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.