Learning PHP sort (): Array Sort

Parameters:
arr is array to be sorted.
sort_mode indicates the sort mode is an optional parameter. sort_mode can use the following values:
SORT_REGULAR: normal comparison element, does not change the type (default) elements.
SORT_NUMERIC: element is to compare as numbers.
SORT_STRING: element is compared as a string.
SORT_LOCALE_STRING: according to the current region (the locale) provided the element as a string comparison, you can setlocale () to change.
SORT_NATURAL: and natsort () Similarly, for each element in a "natural order" sort strings, PHP 5.4.0 is added in a parameter.
SORT_FLAG_CASE: SORT_STRING can be combined with or SORT_NATURAL (OR bit operation), case-insensitive string sort.

sort () after the function call, arr array elements will be rearranged in accordance with the order from high to low.

Return Value: Sort successful returns TRUE, otherwise returns FALSE.
Sorting an array of related functions
sort () function using the example below:

<?php
$num = array(10, 23, 5, 12, 84, 16);
sort($num);
print_r($num);
$language = array("http://c.biancheng.net/php/", "PHP", "Java", "JavaScript", "Python");
sort($language, SORT_STRING);
print_r($language);
?>

Output from running the above program is:

Array
(
    [0] => 5
    [1] => 10
    [2] => 12
    [3] => 16
    [4] => 23
    [5] => 84
)
Array
(
    [0] => Java
    [1] => JavaScript
    [2] => PHP
    [3] => Python
    [4] => htt
)

Guess you like

Origin blog.51cto.com/14646119/2460974