How do I sort a multi-dimensional array by value?

后端 未结 3 1252
难免孤独
难免孤独 2020-12-07 01:52

I have an array as following and I want to order that array by the value of the key \"attack\". First keys of the arrays (15, 13, 18) are ID of some certain ite

3条回答
  •  抹茶落季
    2020-12-07 02:34

    Simply use array_multisort

    foreach ($data as $key => $row) {
        $attack[$key]  = $row['attack'];
    }
    
    // Sort the data with attack descending
    array_multisort($attack, SORT_DESC, $data);
    

    Hope this helps.

提交回复
热议问题