Home  >  Article  >  Backend Development  >  How to reverse array order in php

How to reverse array order in php

王林
王林Original
2020-08-06 16:49:414033browse

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)

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);
?>

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!

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