给定这个数组:
$inventory = array(
array("type"=>"fruit", "price"=>3.50),
array("type"=>"milk", "price"=>2.90),
array("type"=>"pork", "price"=>5.43),
);
Run Code Online (Sandbox Code Playgroud)
我想按价格排序$inventory元素得到:
$inventory = array(
array("type"=>"pork", "price"=>5.43),
array("type"=>"fruit", "price"=>3.50),
array("type"=>"milk", "price"=>2.90),
);
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我试图通过多个键对多维数组进行排序,我不知道从哪里开始.我看着uasort,但不太确定如何为我需要的东西编写函数.
我需要按州,然后是event_type,然后按日期排序.
我的数组看起来像这样:
Array
(
[0] => Array
(
[ID] => 1
[title] => Boring Meeting
[date_start] => 2010-07-30
[time_start] => 06:45:PM
[time_end] =>
[state] => new-york
[event_type] => meeting
)
[1] => Array
(
[ID] => 2
[title] => Find My Stapler
[date_start] => 2010-07-22
[time_start] => 10:45:AM
[time_end] =>
[state] => new-york
[event_type] => meeting
)
[2] => Array
(
[ID] => 3
[title] => Mario Party
[date_start] => 2010-07-22
[time_start] => 02:30:PM
[time_end] => 07:15:PM
[state] => …Run Code Online (Sandbox Code Playgroud)