How to use array_reverse function in php

藏色散人
Release: 2023-02-22 18:12:02
Original
3524 people have browsed it

Usage of array_reverse function in php: [array_reverse(array,preserve)]. This function can reverse the order of elements in the original array, create a new array and return it.

How to use array_reverse function in php

php The array_reverse function is used to return an array in the reverse order of elements. Its syntax is array_reverse(array,preserve). The parameter array is required and refers to the specified array.

(Recommended tutorial: php video tutorial)

How to use the php array_reverse function?

Function: Use the opposite element Returns the array in sequence

Syntax:

array_reverse(array,preserve)
Copy after login

Parameters:

array Required. Specifies an array.

preserve Optional. Specifies whether to retain the original array key names.

Instructions:

Reverse the order of elements in the original array, create a new array and return it. If the second parameter is specified as true, the element's key name remains unchanged, otherwise the key name is lost.

php array_reverse() function usage example 1

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

Output:

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

php array_reverse() function usage example 2

<?php
$a=array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota");
print_r(array_reverse($a));
?>
Copy after login

Output:

Array ( [c] => Toyota [b] => BMW [a] => Volvo )
Copy after login

The above is the detailed content of How to use array_reverse 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!