PHP Learning Notes-arrays (13)

Source: Internet
Author: User
Tags bitwise locale

Krsort (array, type);

Role:

To sort the parameters of an array in descending order

Parameters:

Array: Arrays

Type: optional specifies how the elements/items of the array are arranged. Possible values:

    • 0 = sort_regular-default. Arrange each item in the usual order (standard ASCII, without changing the type).

    • 1 = sort_numeric-Each item is treated as a number.

    • 2 = sort_string-Each item is treated as a string.

    • 3 = sort_locale_string-handles each item as a string, based on the current locale (can be changed by setlocale ()).

    • 4 = sort_natural-handles each item as a string, using a natural sort similar to Natsort ().

    • 5 = sort_flag_case-You can sort strings by combining (bitwise OR) sort_string or sort_natural, not case-sensitive.

return value:

Success returns TRUE, Failure returns false

Example: descending order of key for an array

$a = Array (' 1 ' = ' red ', ' 5 ' = ' Blue ', ' 3 ' = ' 12 '); Krsort ($a);  Print_r ($a); Output: Array ([5] = blue [3] = [1] = + red)


Ksort (array, type);

Role:

Sort the key of an array in ascending order

Parameters:

Array: Arrays

Type: Optional. Specifies how to arrange the elements/items of an array. Possible values:

    • 0 = sort_regular-default. Arrange each item in the usual order (standard ASCII, without changing the type).

    • 1 = sort_numeric-Each item is treated as a number.

    • 2 = sort_string-Each item is treated as a string.

    • 3 = sort_locale_string-handles each item as a string, based on the current locale (can be changed by setlocale ()).

    • 4 = sort_natural-handles each item as a string, using a natural sort similar to Natsort ().

    • 5 = sort_flag_case-You can sort strings by combining (bitwise OR) sort_string or sort_natural, not case-sensitive.

return value:

Success returns TRUE, Failure returns false

Example: Sorting an array key in ascending order

$a = Array (' 1 ' = ' red ', ' 5 ' = ' Blue ', ' 3 ' = ' 12 '); Ksort ($a);  Print_r ($a); Output: Array ([1] = red [3] = [5] = = blue)


List (var1, var2, var3 ...)

Role:

Assigning an element in an array to a variable in a list

Parameters:

VAR1: Variable Name

VAR2: Variable Name

VAR3: Variable Name

return value:

Returns the array after assignment

Example:

$a = Array (' a ' = = ' red ', ' b ' = ' blue ', ' c ' = ' 12 ');  $res = List ($b, $c, $d) = $a;   Print_r ($res); Output: Array ([a] = red [b] = blue [C] + 12)


Natcasesort (Array)

Role:

Use natural sort arrays for case-insensitive bleed

Parameters:

Array: Arrays

return value:

Successful return true, failed to Shanghai false

Example:

$a = Array (' a ' = = ' red ', ' b ' = ' blue ', ' c ' = ' purple '); Natcasesort ($a);  Print_r ($a); Output: Array ([b] = blue [c] = purple [A] = red)


Natsort (Array)

Role:

Sort an array using natural sort

Parameters:

Array: Arrays

return value:

Successful return true, failed to Shanghai false

Example

$a = Array (' a ' = = ' red ', ' b ' = ' blue ', ' c ' = ' purple '); Natsort ($a);  Print_r ($a); Output: Array ([b] = blue [c] = purple [A] = red)



This article from "Snail Crawl" blog, please be sure to keep this source http://10130617.blog.51cto.com/10120617/1896582

PHP Learning Notes-arrays (13)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.