Create Daterange Array of Missing Dates


<?php

//fromDate
2014 - 01 - 22
//toDate
2014 - 02 - 20
//$arr
Array(
    [0] = & gt;
    Array(
        [ISO_DATE] = & gt;
        2014 - 02 - 18[DAY_SUM_AMOUNT] = & gt;
        3000[DAY_SUM_VOLUME] = & gt;
        2[CONVERSION_PCT] = & gt;
        100
    )

    [1] = & gt;
    Array(
        [ISO_DATE] = & gt;
        2014 - 02 - 19[DAY_SUM_AMOUNT] = & gt;
        4000[DAY_SUM_VOLUME] = & gt;
        1[CONVERSION_PCT] = & gt;
        100
    )

)

//codetime
function createDateRangeArray($strDateFrom, $strDateTo)
{
    $aryRange = array();
    $iDateFrom = mktime(1, 0, 0, substr($strDateFrom, 5, 2) , substr($strDateFrom, 8, 2) , substr($strDateFrom, 0, 4));
    $iDateTo = mktime(1, 0, 0, substr($strDateTo, 5, 2) , substr($strDateTo, 8, 2) , substr($strDateTo, 0, 4));
    if ($iDateTo & gt; = $iDateFrom)
    {
        array_push($aryRange, date('Y-m-d', $iDateFrom)); // first entry
        while ($iDateFrom & lt;
        $iDateTo)
        {
            $iDateFrom += 86400; // add 24 hours array_push($aryRange,date('Y-m-d',$iDateFrom)); } } return $aryRange; } function recursive_array_search($needle,$haystack) { foreach($haystack as $key=>$value) {
            $current_key = $key;
            if ($needle === $value or (is_array($value) & amp; & amp;
            recursive_array_search($needle, $value) !== false))
            {
                return $current_key;
            }
        }
        return false;
    }

    $dates = createDateRangeArray($fromDate, $toDate);
    $arr2 = array();
    foreach ($dates as $date)
    {
        $inArr = recursive_array_search($date, $arr);
        if ($inArr !== false)
        {
            array_push($arr2, $arr[$inArr]);
        }
        else
        {
            array_push($arr2, array(
                "ISO_DATE" = & gt;
                $date,
                "DAY_SUM_AMOUNT" = & gt;
                0,
                "DAY_SUM_VOLUME" = & gt;
                0,
                "CONVERSION_PCT" = & gt;
                0
            ));
        }
    }
    $arr = $arr2;