我试图让最常见的小时成为一个数组。 foreach循环是分割值并仅使用小时
获取数组 foreach ($times as $k => $v) {
$avtime[$k] = explode("T", $v);
$avtimeb[$k] = $avtime[$k][1];
foreach ($avtimeb as $kb => $vb) {
$avtimec[$kb] = explode(":", $vb);
$avtimed[$kb] = $avtimec[$kb][0];
}
}
和print_r($avtimed);
生成以下内容:
Array
(
[0] => 08
[1] => 08
[2] => 08
[3] => 08
[4] => 09
[5] => 09
[6] => 08
[7] => 08
[8] => 08
[9] => 10
[10] => 09
[11] => 09
[12] => 10
[13] => 11
[14] => 07
[15] => 08
[16] => 13
[17] => 07
[18] => 08
[19] => 08
[20] => 08
[21] => 09
[22] => 09
[23] => 09
[24] => 09
)
现在我需要从上面得到最常见的价值。
答案 0 :(得分:0)
使用外部阵列可以存储类似的小时。然后浏览数组以获得公共小时。
<强>技术强>
openFolder_1
openFolder_2
答案 1 :(得分:0)
最后一个是:
foreach ($times as $k => $v) {
$avtime[$k] = explode("T", $v);
$avtimeb[$k] = $avtime[$k][1];
foreach ($avtimeb as $kb => $vb) {
$avtimec[$kb] = explode(":", $vb);
$avtimed[$kb] = $avtimec[$kb][0];
}
}
$count = array_count_values($avtimed);
arsort($count);
$keys = array_keys($count);
echo "The most occuring value is $keys[0] and the second one is $keys[1]";
谢谢大家的帮助。