How to reverse array values ​​in php

藏色散人
Release: 2023-03-06 09:26:02
Original
2829 people have browsed it

In PHP, you can use the array_flip function to reverse the key names and corresponding associated key values ​​in the array. The syntax is "array_flip(array);". The parameter array specifies the array that needs to be reversed.

How to reverse array values ​​in php

Recommendation: "PHP Video Tutorial"

array_flip() function is used to reverse/exchange elements in an array Key name and corresponding associated key value.

Syntax

array_flip(array);
Copy after login

Parameters

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

Technical details

Return value: If the inversion is successful, the reversed array is returned. If the reversal fails, NULL is returned.

PHP version: 4

Example:

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

Run result:

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

The above is the detailed content of How to reverse array values ​​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