php二维数组求最大值解决方法

WBOY
Release: 2016-06-13 13:44:55
Original
1638 people have browsed it

php二维数组求最大值
求教各位大牛,现在又一个数组$a={[0]=>{123,张三,45},[1]=>{123,张三,60},[2]=>{234,李四,47},[3]=>{234,李四,68},[4]=>{234,李四,87}},求出张三和李四成绩最大值(最后一个值),不用mysql,只用php的数组操作,希望指教!!!

------解决方案--------------------

PHP code
$a = array(
  array( 123, '张三', 45 ),
  array( 123, '张三', 60 ),
  array( 234, '李四', 47 ),
  array( 234, '李四', 68 ),
  array( 234, '李四', 87 ),
);

foreach($a as $v) {
  if(! $r[$v[1]]) $r[$v[1]] = 999;
  $r[$v[1]] = min($r[$v[1]], $v[2]);
}

print_r($r); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template