PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




PHP Array Elements Sorting Function


Tutorials »Php »

Topic

What is asort() Function?



Explanation

The "asort()" function used to sorting an array elements by the values and keep the original keys.

Syntax:
     asort(array,sorttype)

In the above syntax "array" is the array to be sorted, "sorttype" specifies the method to be used for sorting, it can have values "SORT_REGULAR" for default, "SORT_NUMERIC" treat values numerically, "SORT_STRING" treat values as strings,"SORT_LOCALE_STRING" treat values as strings based on local settings .

Example:
    <?php
    $b=array("1"=>"Grapes","2"=>"Apple","3" =>"Cherry");
    asort($b);
    print_r($b);
    ?>
Result:
    Array
     {
      [2] => Apple
      [3] => Cherry
      [1] => Grapes
     }

In the above example all the elements of the array "$b" is sorted using the default type "SORT_REGULAR" based on the values and the keys remain the same.





A Note

Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial. Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.

Other Links

web hosting