The problem with an array structure such as this is it does not lend itself well to sorting the array by a particular column. As shown in , to take advantage of PHP's native sorting functionality, each column must be stored in its own separate array (keeping the key values synchronized so that index 1 for each array column corresponds to the appropriate value).
Listing 2.15. Creating a Sortable Table Using Arrays
Compare and ; the first thing you'll probably notice is that the second listing appears much cleaner than the original counterpart. Furthermore, because each column in the table is represented by a different PHP array, each column can also be sorted using PHP's internal array functions. To accomplish this sorting, you can use the asort() PHP function.