Home  >  Article  >  Backend Development  >  How to sort array in php without deduplication

How to sort array in php without deduplication

王林
王林Original
2020-10-12 10:29:131751browse

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.

How to sort array in php without deduplication

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!

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