PHP:从多维数组中获取最大值,并返回具有最大值的数组
我有个小问题。 我不知道该怎么做: 输入数据: 我需要的是: 我需要返回带有maxwish_number键值的数组。如果有2个或更多的阵列具有相同的愿望_编号,我需要选择价格最高的阵列 非常感谢各位。你太棒了。你可以使用数组\u多端口来完成这项任务。例如:PHP:从多维数组中获取最大值,并返回具有最大值的数组,php,arrays,Php,Arrays,我有个小问题。 我不知道该怎么做: 输入数据: 我需要的是: 我需要返回带有maxwish_number键值的数组。如果有2个或更多的阵列具有相同的愿望_编号,我需要选择价格最高的阵列 非常感谢各位。你太棒了。你可以使用数组\u多端口来完成这项任务。例如: $wish_number = array_map(function($col){ return $col['wish_number']; }, $data); $price = array_map(function($col){
$wish_number = array_map(function($col){
return $col['wish_number'];
}, $data);
$price = array_map(function($col){
return $col['price'];
}, $data);
array_multisort($data, SORT_DESC, $wish_number, SORT_DESC, $price);
echo '<pre>';
print_r($data);
$max = $data[0];
我的例子
}你想让人给你写这封信吗?或者你想分享你的尝试并让我们帮助你吗?你可能会觉得有用。
$wish_number = array_map(function($col){
return $col['wish_number'];
}, $data);
$price = array_map(function($col){
return $col['price'];
}, $data);
array_multisort($data, SORT_DESC, $wish_number, SORT_DESC, $price);
echo '<pre>';
print_r($data);
$max = $data[0];
usort($data, $this->usort_callback);
$arr = array_slice($data, 0, 1);
public function usort_callback($a, $b)
{
if ($a['wish_number'] == $b['wish_number']) {
if ($a['price'] == $b['price']) {
return ($a['last_added'] > $b['last_added']) ? -1 : 1;
}else{
return ($a['price'] > $b['price']) ? -1 : 1;
}
}
return ( $a['wish_number'] > $b['wish_number'] ) ? -1 : 1;
}