[英]Highest value of one row of a multidimensional array
I have a problem finding out the highest value of one row of a multidimensional array. 我在找出多维数组的一行的最大值时遇到问题。
The array is like: 数组就像:
$array[$days][events]
I am looping from 1 to 31 (the days of a month) to receive the number of events on the day $days. 我从1到31(一个月中的某几天)循环播放,以接收$ days日的事件数。
For the next step I need to know the highest index (value) of the events row. 对于下一步,我需要知道事件行的最高索引(值)。 (Can be any number from 0 to 1293xxxx)
(可以是0到1293xxxx之间的任何数字)
I have already tried count, but it just returns the number of events, not the last event index. 我已经尝试过计数,但是它只返回事件数,而不是最后一个事件索引。
First make an array which contain each day's higher value with max()
, then use max()
on this new array and you're ok 首先用
max()
制作一个包含每天更高价值的数组,然后在这个新数组上使用max()
就可以了
$cnt = 0;
$tab = array();
while (isset($array[$cnt]))
{
$tab[] = max($array[$cnt]);
cnt++;
}
$maxvalue = max($tab);
EDIT: sorry i didn't understand, what i wrote will take the global hightest. 编辑:对不起,我不明白,我写的东西将成为全球最高的。
You just need to use max()
on the table you want. 您只需要在想要的表上使用
max()
。 Good luck 祝好运
Try this 尝试这个
for ($i = 0; $i <= 31; $i++) {
ksort($array[$i], SORT_NUMERIC);
end($array[$i]);
$events[$i] = key($events);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.