Home >Backend Development >PHP Problem >How to sort array in php without deduplication
php method to sort the array without deduplication: [$cars=array("porsche","BMW","Volvo");sort($cars);], which means alphabetically Sorts the elements in an array in ascending order.
Function introduction:
sort() - Sort the array in ascending order
rsort() - Sort the array in descending order Sorting
(Recommended tutorial: php video tutorial)
Example:
Sort the elements in the array $cars in ascending alphabetical order
Code implementation:
<?php $cars=array("porsche","BMW","Volvo"); sort($cars); ?>
Sort the elements in the array $numbers in ascending numerical order
Code implementation:
<?php $numbers=array(3,5,1,22,11); sort($numbers); ?>
Sort the array $ in descending alphabetical order Sort the elements in cars
<?php $cars=array("porsche","BMW","Volvo"); rsort($cars); ?>
Sort the elements in the array $numbers in descending numerical order
<?php $numbers=array(3,5,1,22,11); rsort($numbers); ?>
Related recommendations: php training
The above is the detailed content of How to sort array in php without deduplication. For more information, please follow other related articles on the PHP Chinese website!