How to use array_flip function in php

藏色散人
Release: 2023-02-22 18:06:01
Original
3409 people have browsed it

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);
Copy after login

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);
?>
Copy after login

Output:

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

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);
?>
Copy after login

Output:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template