Home >Backend Development >PHP Problem >How to change the order of array in php
The way PHP changes the order of an array is to use the array_reverse() function to flip the array, such as [$preserve=array_reverse($a,true);].
The operating environment of this article: windows10 system, php 7.1, thinkpad t480 computer.
In PHP we have many ways to change the order of an array, but one of the most convenient methods is to directly flip the array. PHP provides a function array_reverse() function, which can reverse the sequence of arrays easily and quickly.
Next let’s take a look at how to use this function.
Output the original array, flipped array, and flipped array retaining the original array key names:
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); ?>
Friends can run the above code locally Down.
Recommended learning: php training
The above is the detailed content of How to change the order of array in php. For more information, please follow other related articles on the PHP Chinese website!