How to sort array in php without deduplication

王林
Release: 2023-03-06 16:26:01
Original
1752 people have browsed it

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);
?>
Copy after login

Sort the elements in the array $numbers in ascending numerical order

Code implementation:

<?php
$numbers=array(3,5,1,22,11);
sort($numbers);
?>
Copy after login

Sort the array $ in descending alphabetical order Sort the elements in cars

<?php
$cars=array("porsche","BMW","Volvo");
rsort($cars);
?>
Copy after login

Sort the elements in the array $numbers in descending numerical order

<?php
$numbers=array(3,5,1,22,11);
rsort($numbers);
?>
Copy after login

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!

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