As with other programming languages, in PHP also sorting arrays and their values have a high importance.
An array can be sorted in ascending or descending order and with numerous functions that use numerical or alphabetical approach.
Syntax for basic array sorting
$arrays = ("value1", "value2", "value3");
sort ($arrays); // ascending order
rsort ($arrays); // descending order
Following functions may be used in array sorting:
- sort() - sorting ascending
- rsort() - sorting descending
- asort() - sorting ascending of associative array
- ksort() - sorting ascending of associative array according to key
- arsort() - sorting descending of associative array
- krsort() - sorting descending of associative array according to key
Examples of array sorting
Comments
No comments have been made yet.
Please login to leave a comment. Login now