Javatpoint Logo
Javatpoint Logo

PHP asort() function

The asort( ) function is an inbuilt function of PHP. The asort( ) function is used to sort an associative array in ascending order, according to the value. This function was introduced in PHP 4.0.

Syntax

Parameters

Parameter Description Is compulsory
array Specifies the name of the array to sort. compulsory
Sort_flags Specifies how to compare the array elements. Optional

Return

It returns true on success or false on failure.

Example 1

Output:

Array
(
    [virat] => 29
    [ganguly] => 39
    [sachin] => 42
)

Example 2

Output:

Array
(
    [G] => Black
    [W] => Cyan
    [Y] => Green
    [B] => White
    [C] => Yellow
)

Example 3

Output:

Array
(
    [compiler] => 68
    [data structure] => 89
    [OS] => 95
)

Example 4

Output:

Array
(
    [b] => Geography
    [d] => Hindi
    [c] => Math
    [a] => Science
)





Help Others, Please Share

facebook twitter pinterest