How to sort an array of associative arrays by value of a given key in PHP?

前端 未结 19 1819
清酒与你
清酒与你 2020-11-21 23:34

Given this array:

$inventory = array(

   array(\"type\"=>\"fruit\", \"price\"=>3.50),
   array(\"type\"=>\"milk\", \"price\"=>2.90),
   array(\"         


        
19条回答
  •  鱼传尺愫
    2020-11-22 00:12

    try this:

    asort($array_to_sort, SORT_NUMERIC);
    

    for reference see this: http://php.net/manual/en/function.asort.php

    see various sort flags here: http://www.php.net/manual/en/function.sort.php

提交回复
热议问题