2个数组,需要的结果才是我所展示的

时间:2014-07-25 10:06:15

标签: php mysql arrays

这是我的数组,我想在下面得到这个结果,但是无法弄明白。

结果是ID在2014-06-01到2014-06-xx的最后一天之间有多少次的计数

在包含日期"数组[1]"的数组中,只有6-7-8的日期错误。

请帮助:-S

RESULT

Array
(

[0] => Array
    (
        [1] => 2
        [4] => 2
        [7] => 3
        [9] => 1
        [12] => 1
        [13] => 1
    )
)


Array
(

[0] => Array
    (
        [0] => 4
        [1] => 4
        [2] => 7
        [3] => 1
        [4] => 7
        [5] => 7
        [6] => 3
        [7] => 3
        [8] => 4
        [9] => 9
        [10] => 12
        [11] => 2
        [12] => 13
        [13] => 1
    )
[1] => Array
    (
        [0] => 2014-06-18
        [1] => 2014-06-10
        [2] => 2014-06-05
        [3] => 2014-06-05
        [4] => 2014-06-12
        [5] => 2014-06-11
        [6] => 2013-12-12
        [7] => 2014-07-23
        [8] => 2014-05-13
        [9] => 2014-06-01
        [10] => 2014-06-12
        [11] => 2014-06-04
        [12] => 2014-06-04
        [13] => 2014-06-11
    )

)

1 个答案:

答案 0 :(得分:0)

希望以下工作。没试过。

$idsArray = $yourArray[0];
$dateArray = $yourArray[1];
$countArray = array(); // the result array

$beginningTimestamp = strtotime('2014-06-01');
$lastTimestamp = strtotime('2014-07-01');  // before the first of July comes the last of June

foreach ($idsArray as $key => $id) {
   if (isset($dateArray[$key])) {
     $timestamp = strtotime($dateArray[$key];
     if ($timestamp >= $beginningTimestamp && $timestamp < $lastTimestamp) {
        if (isset($countArray[$id])) {
           $countArray[$id]++;
        } else {
           $countArray[$id] = 1;
        }
     }
   } 
}