Home >Backend Development >PHP Problem >How to use array_flip function in php

How to use array_flip function in php

藏色散人
藏色散人Original
2019-05-24 15:15:003447browse

Usage of array_flip function in php: [array_flip(array)]. The array_flip function is used to reverse all the key names and their associated key values ​​​​in the array, and return the reversed array.

How to use array_flip function in php

php array_flip function is used to reverse/exchange all key names and their associated key values ​​​​in the array. Its syntax is array_flip(array), parameter array Required, specifies the array whose key/value pairs need to be reversed.

(Recommended tutorial: php video tutorial)

How to use the php array_flip function?

Function: Used to reverse/exchange all key names and their associated key values ​​in the array.

Syntax:

array_flip(array);

Parameters:

array Required. Specifies the array whose key/value pairs need to be reversed.

Description:

Returns a reversed array. If the same value appears multiple times, the last key name will be its value, and all other keys will be used. Names will be lost. If the data type of the value in the original array is not string or integer, the function will report an error.

php array_flip() function usage example 1

<?php
$a = array("class" => "php中文网","name" => "西门","job" => "讲师");
$result=array_flip($a);
print_r($result);
?>

Output:

Array ( [php中文网] => class [西门] => name [讲师] => job )

php array_flip() function usage example 2

<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$result=array_flip($a1);
print_r($result);
?>

Output:

Array ( [red] => a [green] => b [blue] => c [yellow] => d )

The above is the detailed content of How to use array_flip function in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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