Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

Implementing Arrays
 
Article Index
Implementing Arrays
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8
Page 9
Page 10
 

Although a number of sorting functions are available to the PHP developer, this particular sorting function has been chosen because of one critical detailit maintains the association of key/value pairs (see the discussion of array_filter() earlier in this chapter for more information on the importance of this). The syntax for the asort() function is as follows:

asort($input [, $sort_flag]);

NOTE

The asort() function orders arrays from smallest to largest (or alphabetically from AZ). If the opposite behavior is desired, the arsort() function can be used in the same manner as asort().


$input represents the array to be sorted, and $sort_flag is an optional parameter (a constant) specifying the type of sort to perform. Note that the constants specified by the sort_flag parameter are not PHP variables. They are constant values predefined within PHP (much like what can be created using the define statement). The three possible values for the sort_flag parameter are shown in :

Table 2.1. asort() Constants

SORT_REGULAR

Compare the items normally (default).

SORT_NUMERIC

Compare the items as numeric values.

SORT_STRING

Compare the items as string values.


When executed, the asort() function will sort the $input array as determined by sort_flag (no return value).

Implementing the asort() function to sort and maintain your table structure becomes a relatively simple task because each column of your table is stored in a separate array. Use the asort() function to sort whichever column is desired, and then use the foreach() function to display the sorted data in an HTML table, as shown in , which sorts the table by the Weight column:



Tags: Add more tags...,
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Natural 30
Statistic


Last Post

 
Top! Top!