PHP sort multidimensional array with primary & secondary keys

后端 未结 4 548
无人共我
无人共我 2021-01-13 11:17

How do you sort a multidimensional array by primary and secondary key? For example, assuming the following array:

$result = array();

$result[0][\"prio\"] =          


        
4条回答
  •  既然无缘
    2021-01-13 12:17

    You may use usort() to define custom sort function.
    Here's an example

     $value) {
        echo "$key: $value\n";
    }
    ?>
    

    The output will be

    0: 1
    1: 2
    2: 3
    3: 5
    4: 6
    

    More info can be found at http://www.php.net/manual/en/function.usort.php
    It should help you get started.

提交回复
热议问题