Php Array Elements Sort Function

What is sort Function?


The "sort" function sorts elements of an array.


sort(array,sort type)

In the above syntax "array" is the array to be sorted. The "sort type" specifies the type in which the elements to be sorted, for example "SORT_REGULAR",is the default type, "SORT_NUMERIC", treat values numerically, "SORT_STRING", treat values as strings, "SORT_LOCALE_STRING", treat values as string based on local setting.

Example :

$b=array("a"=>"Grapes","b"=>"Apple","c" =>"Cherry");
Result :

[0] => Apple
[1] => Cherry
[2] => Grapes

In the above example the array "$b" is sorted, displays the elements value starting from "Apple".

PHP Topics

Ask Questions

Ask Question