PHP求某二维数组,某一列元素的最大最小值

<?php
$box = array(
  0 =>array( 
    'boxnum' => 1, 
    'record' => 66
    ),
  1 =>array( 
    'boxnum' => 2, 
    'record' => 66
    ),
  2 =>array( 
    'boxnum' => 3, 
    'record' => 66
    )
);

//求boxnum这一列的最大值
$max = 0;
foreach ($box as $key => $val) {
  $max = max($max , $val['boxnum']);
};
//求boxnum这一列的最小值
$min = $max;(上一步求的最大值)
foreach ($box as $key => $val) {
  $min = min($min , $val['boxnum']);
};
echo $max;
echo $min;

?>

 

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页