How to use sort function

藏色散人
Release: 2023-04-05 08:20:01
Original
4522 people have browsed it

php sort() function is used to sort arrays.

How to use sort function

php sort() function Syntax

Function: Sort the index array in ascending order.

Syntax:

sort(array,sortingtype);
Copy after login

Parameters:

array Required. Specifies the array to be sorted.

sortingtype Optional. Specifies how elements/items of an array are compared. Possible values: 0 = SORT_REGULAR - Default. Put each item in regular order (Standard ASCII, don't change the type). 1 = SORT_NUMERIC - treat each item as a number. 2 = SORT_STRING - Treat each item as a string. 3 = SORT_LOCALE_STRING - Treat each item as a string, based on the current locale (can be changed with setlocale()). 4 = SORT_NATURAL - Treat each item as a string, using natural sorting like natsort(). 5 = SORT_FLAG_CASE - Strings can be sorted in combination (bitwise OR) with SORT_STRING or SORT_NATURAL, case-insensitively.

Description: This function assigns a new key name to the unit in the array. The original key name will be deleted. Returns TRUE if successful, FALSE otherwise.

php sort() function example

<?php
$a=array("a"=>"php中文网","b"=>"西门","c"=>"php.cn");
sort($a);
print_r($a);
?>
Copy after login

Output:

Array ( [0] => php.cn [1] => php中文网 [2] => 西门 )
Copy after login

This article is an introduction to the PHP sort function. I hope it will be helpful to friends who need it. Helps!

The above is the detailed content of How to use sort function. 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