The asort() function is an inbuilt function in PHP which is used to sort an array according to values. It sorts in a way that relation between indices and values is maintained. By default it sorts in ascending order of values.
bool asort( $array, $sorting_type )
Parameters: This function accepts two parameters as mentioned above and described below:
- $array: This parameter specifies the array which to be sort. It is a mandatory parameter.
- $sorting_type: This is an optional parameter. There are different sorting types which are discussed below:
- SORT_REGULAR: The value of $sorting_type is SORT_REGULAR then items are compare normally.
- SORT_NUMERIC: The value of $sorting_type is SORT_NUMERIC then items are compares numerically.
- SORT_STRING: The value of $sorting_type is SORT_STRING then items are compares as string.
- SORT_LOCALE_STRING: The value of $sorting_type is SORT_STRING then items are compares as string, based on current locale.
Return Value: This function returns True on success or False on failure.
Below programs illustrate the asort() function in PHP.
 = Article  = Computer Graphics  = Copy  = Gate Note  = GeeksforGeeks  = IDE  = Machine Learing  = Report Bug  = Reset  = SContribute  = Sudo Placement  = Videos  = Web Technology
[q] = -11 [z] = 1 [s] = 2 [t] = 3 [a] = 11 [b] = 22 [d] = 33 [n] = 44 [o] = 55 [p] = 66 [r] = 77 [u] = 1000
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.