Codeigniter按日期排序多功能

时间:2019-09-03 04:16:21

标签: php codeigniter

$data['reg'] = $this->register->registerAcc($schoolID); 
$data['upd'] =$this->register->UpdateAcc($schoolID); 
$data['sus'] =$this->register->suspendAcc($schoolID);
$this->load->view('account/accountInfo',$data);

这是我的代码,由更新,注册和挂起组成。每个功能都有自己的“日期/时间”

函数的每个末端都有以下代码:

  

$ this-> db-> order_by('register_Date','DESC');
  每个函数都有自己的日期,例如register_Date,updateAcc_Date

但是我有一个问题,当我在页面中显示列表时,将来自

Date           Function       UserName
05-09-2019  Register    Tom
04-09-2019  Register    Bors
01-09-2019  Register    Berry
03-09-2019  Update      Laxy    
05-09-2019  Suspend     Loi

我想要的是

Date           Function       UserName
05-09-2019  Register    Tom
05-09-2019  Suspend     Loi
04-09-2019  Register    Bors
03-09-2019  Update      Laxy    
01-09-2019  Register    Berry

1 个答案:

答案 0 :(得分:0)

date数组中使用与$data相同的键设置日期,然后使用usort()函数

$data = Array
(

[0] => Array
    (
        [Function] => 'register'
        [datetime] => 2010-05-26 15:59:53
    )

[1] => Array
    (
       [Function] => 'update'
        [datetime] => 2010-05-26 16:04:24
    )

)
 function date_compare($a, $b)
    {
        $t1 = strtotime($a['datetime']);
        $t2 = strtotime($b['datetime']);
        return $t1 - $t2;
    }    
    usort($data, 'date_compare');
    print_r($data);