Sorting an Associative Array by Column Value
Given an array of associative arrays, the task is to sort the elements based on a specific column value.例如,考慮以下數組:
目標是按“價格”列對$庫存進行排序,導致:$inventory = array( array("type" => "fruit", "price" => 3.50), array("type" => "milk", "price" => 2.90), array("type" => "pork", "price" => 5.43), );這是一個示例:
= $ row ['price']; } array_multisort($ price,sort_desc,$ neventory);
通過排序$ price Array,我們間接排序$庫存,因為它們共享相同的鍵。免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3