Generally sorting refers to arranging or ordering data based on some category. In php also sorting functions are used to order the array elements.
Some of the sorting functions are..
- sort() - sort arrays in ascending order in indexed array
- rsort() - sort arrays in descending order in indexed array
- asort() - sort associative arrays in ascending order, according to the value
- arsort() - sort associative arrays in descending order, according to the value
- ksort() - sort associative arrays in ascending order, according to the key
- krsort() - sort associative arrays in descending order, according to the key
Example program for sort():
- Sort arrays in ascending order
1
2
3
4
5
2
3
4
5
- Sort arrays in descending order
5
4
3
2
1
4
3
2
1
- Sort associative arrays in ascending order, according to the value
10
20
30
40
20
30
40
- Sort associative arrays in descending order, according to the value
40
30
20
10
30
20
10
- Sort associative arrays in ascending order, according to the Key
10
40
20
30
40
20
30
Example program for krsort():
- Sort associative arrays in descending order, according to the Key
30
20
40
10
20
40
10
No comments:
Post a Comment