关联数组的Hightest价值 [英] Hightest value of an associative array
本文介绍了关联数组的Hightest价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有简单的方法来获得一个关联数组的hightest数值?
Is there any easy way to get the hightest numeric value of an associative array?
$array = array(
0 => array(
'key1' => '123',
'key2' => 'values we',
'key3' => 'do not',
'key4' => 'care about'
),
1 => array(
'key1' => '124',
'key2' => 'values we',
'key3' => 'do not',
'key4' => 'care about'
),
2 => array(
'key1' => '125',
'key2' => 'values we',
'key3' => 'do not',
'key4' => 'care about'
)
);
AwesomeFunction($array, 'key1'); // returns 2 ($array key)
请善待,因为这个问题是用手机写的。谢谢你。
Please be kind since this question was written with a phone. Thanks.
推荐答案
如果你知道你的数据总是会在该格式,这样的事情应该工作。
If you know your data will always be in that format, something like this should work.
function getMax( $array )
{
$max = 0;
foreach( $array as $k => $v )
{
$max = max( array( $max, $v['key1'] ) );
}
return $max;
}
这篇关于关联数组的Hightest价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文