douqianke7467 2011-11-02 19:28
浏览 15
已采纳

如何在php中安排数组中的不同值?

i have this situation:

print_r($key);echo'<br>'; 
foreach($value as $test){
print_r(count($test));echo'<br>'; 
}
echo'<br>'; 

witch returns:

Jerome Frier
2
5
1

Luke Saora
5
4
6

Tracy Edion
6
1
4

what i am aiming for is to display the maximum value for each name, like this:

Jerome Frier          Luke Saora           Tracy Edion
    6                     5                     6

basically taking the maximum value for each name comparing each row..

does this sound confuse... :)

thanks

  • 写回答

3条回答 默认 最新

  • dsf1222 2011-11-02 19:34
    关注

    If I were you I'd just make use of PHP's max function. If the first and only parameter is an array, max() returns the highest value in that array. If at least two parameters are provided, max() returns the biggest of these values.

    So either you put all the values in an array and throw it into the max() function, or you insert them one by one..

    $max = max($your_values); //where $your_values is an array
    //or
    $max = max($value1, $value2, $value3); //where $value is a single value
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?