获得每个" Carrier"最低费率的最佳方法是什么?
Array
(
[0] => Array
(
[Method] => SMART_POST
[Title] => Smart Post
[Price] => 8.58
[Carrier] => fedex
[Carrier Title] => Fedex
[Description] =>
)
[1] => Array
(
[Method] => GROUND_HOME_DELIVERY
[Title] => Home Delivery
[Price] => 12.34
[Carrier] => fedex
[Carrier Title] => Fedex
[Description] =>
)
[2] => Array
(
[Method] => FEDEX_EXPRESS_SAVER
[Title] => Express Saver
[Price] => 16.25
[Carrier] => fedex
[Carrier Title] => Fedex
[Description] =>
)
[3] => Array
(
[Method] => FEDEX_2_DAY
[Title] => 2 Day
[Price] => 20.49
[Carrier] => fedex
[Carrier Title] => Fedex
[Description] =>
)
[4] => Array
(
[Method] => PRIORITY_OVERNIGHT
[Title] => Priority Overnight
[Price] => 32.17
[Carrier] => fedex
[Carrier Title] => Fedex
[Description] =>
)
[5] => Array
(
[Method] => 4
[Title] => Standard Post
[Price] => 8.76
[Carrier] => usps
[Carrier Title] => United States Postal Service
[Description] =>
)
[6] => Array
(
[Method] => 1
[Title] => Priority Mail 3-Day
[Price] => 10.25
[Carrier] => usps
[Carrier Title] => United States Postal Service
[Description] =>
)
[7] => Array
(
[Method] => 3
[Title] => Priority Mail Express 2-Day
[Price] => 38.8
[Carrier] => usps
[Carrier Title] => United States Postal Service
[Description] =>
)
)
使用上面的数组,结果将是
fedex Smart Post 8.58 usps Standard Post 8.76
答案 0 :(得分:1)
试试这个
$arr = Array
(
0 => Array
(
'Method' => 'SMART_POST',
'Title' => 'Smart Post',
'Price' => '8.58',
'Carrier' => 'fedex',
'Carrier Title' => 'Fedex',
'Description' =>''
),
1 => Array
(
'Method' => 'GROUND_HOME_DELIVERY',
'Title' => 'Home Delivery',
'Price' => '12.34',
'Carrier' => 'fedex',
'Carrier Title' => 'Fedex',
'Description' =>''
),
2 => Array
(
'Method' => 'FEDEX_EXPRESS_SAVER',
'Title' => 'Express Saver',
'Price' => '16.25',
'Carrier' => 'fedex',
'Carrier Title' => 'Fedex',
'Description' =>''
),
3 => Array
(
'Method' => 'FEDEX_2_DAY',
'Title' => '2 Day',
'Price' => '20.49',
'Carrier' => 'fedex',
'Carrier Title' => 'Fedex',
'Description' =>''
),
4 => Array
(
'Method' => 'PRIORITY_OVERNIGHT',
'Title' => 'Priority Overnight',
'Price' => '32.17',
'Carrier' => 'fedex',
'Carrier Title' => 'Fedex',
'Description' =>''
),
5 => Array
(
'Method' => 4,
'Title' => 'Standard Post',
'Price' => '8.76',
'Carrier' => 'usps',
'Carrier Title' => 'United States Postal Service',
'Description' =>''
),
6 => Array
(
'Method' => 1,
'Title' => 'Priority Mail 3-Day',
'Price' => '10.25',
'Carrier' => 'usps',
'Carrier Title' => 'United States Postal Service',
'Description' =>''
),
7 => Array
(
'Method' => 3,
'Title' => 'Priority Mail Express 2-Day',
'Price' => '38.8',
'Carrier' => 'usps',
'Carrier Title' => 'United States Postal Service',
'Description' =>''
)
);
usort($arr, function($a, $b) {
return $a['Price'] - $b['Price'];
});
print_r($arr);