August 2003
Intermediate to advanced
1104 pages
19h 27m
English
Usually, it will not be necessary to write your own sort functions. PHP offers several functions for sorting arrays. The most basic is sort. This function is described, along with the other sorting functions in Chapter 11. It's instructive to compare sort to rsort, asort, and ksort.
The sort function puts all the elements in the array in order from lowest to highest. If the array contains any strings, then this means ordering them by the ASCII codes of each character. If the array contains only numbers, then they are ordered by their values. The indices—the values used to reference the elements—are discarded and replaced with integers starting with zero. This is an important effect, which Listing 21.1 demonstrates; ...