PHP Sort Array Data
In PHP, sort array data means organising elements of array in ascending or descending order, increasing order or decreasing order as you require. PHP has some functions which hepls you to sort the array value in ascending and descending order as you desire.
Sorting operation can be performed on both:
- Indexed Array
- Associative Array
Sort Array Alphabetical in Ascending Order
This can be done with the use of sort() function.
Sort Array Alphabetical in Ascending Order Example
This will produce following result
Sort Numerical Array in Inceasing Order
This can also be done with the use of sort() function.
Sort Numerical Array in Inceasing Order Example
This will produce following result
Sort Alphabetical Array in Descending Order
This can be done with the use of rsort() function.
Sort Alphabetical Array in Descending Order Example
This will produce following result
Sort Numerical Array in Decreasing Order
This can also be done with the use of rsort() function.
Sort Numerical Array in Decreasing Order Example
This will produce following result
Sort an Associative Arrays in Ascending Order
This can be done with the use of asort() function.
Sort an Associative Arrays in Ascending Order Example
Sort an Associative Arrays in Ascending Order
This can be done with the use of ksort() function.
Sort an Associative Arrays in Ascending Order Example
Sort an Associative Arrays in Descending Order
This can be done with the use of arsort() function.
Sort an Associative Arrays in Descending Order Example
Sort an Associative Arrays in Descending Order
This can be done with the use of krsort() function.
Sort an Associative Arrays in Descending Order Example