What we are bringing to you today is aThe prototype of the function is Array_multisort ($sortKeyArray, $ascOrDesc, $sortArray), and the PHP array sort function Array_ The first parameter in Multisort is an array of sorted columns to be constructed in order to maintain the corresponding relationship of the array key values, the second parameter is a predefined constant, SORT_ASC-sorted by ascending order, Sort_desc-sorted by descending order, and the third parameter is the array to be sorted. There is also a default parameter that is sorted by the data type, which is skipped here. Take a look at the example below and it will be clear.
- php
- Class Storage
- {
- function Getselllist ()
- {
- Global $db;
- $db- > query ("Set names UTF8");
- $db- > query ("SELECT * from Sold_record");
- While ($row= $db->get_array ())
- {
- $array []= $row;
- }
- $db- > Free ();
- return $array;
- }
- }
- $ Storage = New Storage ();
- $ selllist = $storage- > getselllist ();
- foreach ($sellList as $key => $row)
- {
- $cust [$key] = $row [' customer_id '];
- $prod [$key] = $row [' Product '];
- $pty [$key] = $row [' PType '];
- $SDT [$key]= $row [' sell_date '];
- }
- $ Asdes = "Yes" ;
- if ($_get[up]== "yes")
- {
- $ Asdes = "No" ;
- $ Sort = Sort_desc ;
- }
- ElseIf ($_get[up]== "no")
- {
- $ Asdes = "Yes" ;
- $ Sort = SORT_ASC ;
-
- }
-
- Switch ($_get[order])
- {
- Case "CNAME":
- Array_multisort ($cust, $sort, $sellList);
- Break
- Case "Product":
- Array_multisort ($prod, $sort, $sellList);
- Break
- Case "PType":
- Array_multisort ($pty, $sort, $sellList);
- Break
- Case "Date":
- Array_multisort ($SDT, $sort, $sellList);
- Break
- }
-
- ?>
The above code is the PHP array sorting function array_multisort the specific code to sort the table.
http://www.bkjia.com/PHPjc/446380.html www.bkjia.com true http://www.bkjia.com/PHPjc/446380.html techarticle What we bring to you today is the prototype of a function is Array_multisort ($sortKeyArray, $ascOrDesc, $sortArray), and the PHP array sort function Array_ The first parameter in Multisort is to protect ...