Array_flip () of the sequence of PHP array functions swap the array key name with the value _php tips

Source: Internet
Author: User

Array_flip () Definition and usage

The Array_flip () function swaps the key name of the array with its corresponding value, where the key name becomes a value and the value becomes the key.

The Array_flip () function returns an inverted array, and if the same value occurs more than once, the last key name is the value and all other key names are lost.

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

Grammar
Array_flip (Array) parameter description
Array required. A specified array of inputs.

Example

Copy Code code as follows:

<?php
$a =array (0=> "Dog",1=> "Cat",2=> "horse");p Rint_r (Array_flip ($a));
?>

Output:

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

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.