Home >Backend Development >PHP Tutorial >php二维数组求最大值解决方法

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

WBOY
WBOYOriginal
2016-06-13 10:11:291351browse

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>
Statement:
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