Sort Multi-dimensional Array by given indexes - PHP?

前端 未结 3 801
我寻月下人不归
我寻月下人不归 2021-01-24 21:29

I have two array $days_order and $mysql_result, I want to sort $mysql_result array using $days_order array. I want to display

3条回答
  •  太阳男子
    2021-01-24 22:08

    Use usort with a custom compare function.

    Something like:

    usort($ranked, function($a, $b) {
        if ($a['day'] === $b['day']) return 0;
    
        return ($a['day'] > $b['day']) ? -1 : 1;
    });
    

    You can read more about this function here.

提交回复
热议问题