Combine two array and order this new array by date

后端 未结 3 1793
时光说笑
时光说笑 2021-02-19 13:58

. I have two array

First One

 Array
    (
        [0] => Array
            (
                [date] => 2012-01-10
                [result] => 65         


        
3条回答
  •  暖寄归人
    2021-02-19 14:04

    array_merge your arrays and then use the following code as an example of how you can sort it.

    function sortDate($val1, $val2)
    {
        if ($val1['date'] == $val2['date']) {
            return 0;
        }
    
        return (strtotime($val1['date']) < strtotime($val2['date'])) ? -1 : 1;
    }
    
    $array = array(
        array('date' => '2012-01-10'),
        array('date' => '2011-01-10'),
        array('date' => '2012-01-01')
    );
    
    usort($array, "sortDate");
    print_r($array);
    

提交回复
热议问题