Here below is my code.
I'm trying to plot graph values using the below array.
On the dates
array i have all 30 days in the array.
I have another array called pending_date
and approved_date
.
I need to match the date.Add the key and value for the matching key(date) array. Can u tell me where I'm going wrong ?
$approved_date = array('2017-09-01'=>'1','2017-09-02' => '2', '2017-09-03' => '4');
$pending_date = array('2017-09-01'=>'2');
$rejected_date = array();
Tried Code
$myYearMonth = date('Y-m');
$start = new DateTime(date('Y-m-01', strtotime($myYearMonth)));
$end = new DateTime(date('Y-m-t', strtotime($myYearMonth)).' +1 day');
$diff = DateInterval::createFromDateString('1 day');
$periodStart = new DatePeriod($start, $diff, $end);
foreach ( $periodStart as $dayDate ){
$dates[]['period'] = $dayDate->format( "Y-m-d" );
}
foreach( $pending_date as $key => $value ){
$data_key = array_search( $key, $dates );
if( $data_key !== false ) $dates[ $data_key ] = $value;
}
Expected Output
{"period": "2017-09-01", "approved": 1, "pending": 2, "rejected": 0},
{"period": "2017-09-02", "approved": 2, "pending": 0, "rejected": 0},
{"period": "2017-09-03", "approved": 4, "pending": 0, "rejected": 0}