How to use the PHP array sorting function array_multisort to sort tables. What we bring to you today is the original form of a function: array_multisort ($ sortKeyArray, $ ascOrDesc, $ sortArray ), the first parameter in the PHP array sorting function array_multisort is to ensure that what we bring to you today isThe original form of the function is array_multisort ($ sortKeyArray, $ ascOrDesc, $ sortArray ), the first parameter in the PHP array sorting function array_multisort is the sort column array to maintain the correspondence between the array key values. The second parameter is a predefined constant, SORT_ASC-sort by ascending order, SORT_DESC-sort by descending order, and the third parameter is the array to be sorted. Another default parameter is the sort data type, which is skipped here. You can see the following example in detail.
- 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 code above is the specific code of the PHP array sorting function array_multisort for table sorting.
The original form of the sort function is array_multisort ($ sortKeyArray, $ ascOrDesc, $ sortArray). The first parameter in the PHP array sort function array_multisort is to protect...