[code lang=”php”]

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

[1] => Array
(
[ISO_DATE] => 2014-02-19
[DAY_SUM_AMOUNT] => 4000
[DAY_SUM_VOLUME] => 1
[CONVERSION_PCT] => 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>=$iDateFrom) {
array_push($aryRange,date(‘Y-m-d’,$iDateFrom)); // first entry
while ($iDateFrom<$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) && 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”=>$date, “DAY_SUM_AMOUNT”=>0, “DAY_SUM_VOLUME”=>0, “CONVERSION_PCT”=>0));
}
}
$arr = $arr2;
[/code]

Categories: ContentGeneral

Leave a Reply

Your email address will not be published. Required fields are marked *