sort a multidimensional array using array_multisort

后端 未结 4 1333
感情败类
感情败类 2020-12-17 17:07

I have this array

Array
(
    [0] => Array
        (
            [brand] => blah blah
            [location] => blah blah
            [address] =>         


        
4条回答
  •  盖世英雄少女心
    2020-12-17 17:33

    You need to extract all the distances first, then pass both the distance and the data to the function. As shown in example 3 in the array_multisort documentation.

    foreach ($data as $key => $row) {
        $distance[$key] = $row['distance'];
    }
    
    array_multisort($distance, SORT_ASC, $data);
    

    This assumes you want the shortest distances first, otherwise change the SORT_ASC to SORT_DESC

提交回复
热议问题