How to reverse array order in php

王林
Release: 2023-03-03 22:40:02
Original
4054 people have browsed it

How to reverse the order of an array in php: You can use the array_reverse() function to reverse the array. Function syntax: [array_reverse(array,preserve)], the parameter preserve specifies whether to retain the key name of the original array.

How to reverse array order in php

array_reverse() function returns an array in reverse order.

(Recommended tutorial: php graphic tutorial)

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.

(Video tutorial recommendation: Introduction to Programming)

Code implementation:

<?php
$a=array("Volvo","XC90",array("BMW","Toyota"));
$reverse=array_reverse($a);
$preserve=array_reverse($a,true);
print_r($a);
print_r($reverse);
print_r($preserve);
?>
Copy after login

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