如何运用PHP数组排序函数array_multisort进行表格排序
我们今天为大家带来的是一个PHP数组排序函数array_multisort对数据库表格进行排序的例子,以此来进一步了解PHP语言的概念,增加我们的编码经验。
- 解析PHP5析构函数的具体使用方法
- PHP5魔术函数的具体应用讲解
- PHP mysqli如何连接MySQL数据库
- 简单实现PHP5多重继承
- PHP二维数组排序的具体方法介绍
- <?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;
- }
- ?>
上面这段代码就是PHP数组排序函数array_multisort对表格排序的具体代码编写。
PHP之友评论