Sort in the second array
The sort of arrays is a problem that people who are very headache. The exquisite method of various names will make people halo, but it is important, so that we can't focus on it. Fortunately, PHP has provided a lot of sorted functions, so you can not understand the details of these sort. Comparison of principles and efficiency of sorting, we will be discussed in the chapters of the rear.
The most general sort function in PHP is sort (), and the PHP manual is described below:
Sort (PHP 3, PHP 4) Sort - Randle the array Description Void Sort (Array Array [, int Sort_Flags] This function is sorted to the array. When the end of this function, the array unit will be rearranged from the lowest to the highest.
Using sort () will rearrange the original array according to the ASCII code from small to large order, note that sort () is a direct pair of array and does not return any values. Now let's go back to mahjong :)), MajiangArray's array element is like this: color color _ points. GIF, we need to sort this: First, according to the color color, the MaijiangaRray array, and each color is inside, according to points Sort in size. Obviously, the Sort () function on the upper side is in line with this requirement. We only need to be ok before ShoWarray.
PHP Code
// Sort () sort ($ USER2); Sort ($ USER2); Sort ($ USER3); Sort ($ USER1); Showarray ($ USER2); ShowArray ($ USER2); SHOWArray ($ user2); ShowArray ($ USER4);
The effect chart of the program run is as follows:
The example of the upper exemption can be solved because we pre-organized the content of the elements in advance (), and put the main sort standard - color color in front, and the secondary sorting standard - the number of points is placed behind, and Split them is the same symbol "_". If there is an element 10_10.gif, then the existing order will be disrupted; and the method of reinaged the name of the restructuring is always uncomfortable. This indicates that simple sorting is actually not practical because we are usually sorted in accordance with a feature of array elements. In practical applications, we store array elements with multiple properties through multi-dimensional arrays. For example, an example, we use the user_info to store the accesser's information, visitors ID, visitors' IP, access date, and time, language, and reference pages are saved in user_info ["ID"], user_info [IP "], user_info [" date "], user_info [" time "], user_info [" language "] and user_info [" Reference "]. If we need to sort the USER_ INFO array according to the access time, sort () is useless to the hero. Fortunately, the PHP provides a function array_multisort () for multi-dimensional array sorting, which can be sorted according to one property of a multi-dimensional array of properties. Let's take a look at its role.
PHP Code
php / ** ****************************************************** *************** * A multi-dimensional array sorted example * @ easy@bjpeu.edu.cn * @ 2003-6-6 ** ********* *********************************************************** ** / / / Display function, display the form of a form Function Showuser ($ USERARRAY) {echo '