I have two arrays in PHP as follows,
Resultant array:
Array
(
[0] => Array
(
[month] => Dec 2016
[count] => 2
)
[1] => Array
(
[month] => Feb 2017
[count] => 2
)
)
Month Array:
Array
(
[0] => Dec 2016
[1] => Jan 2017
[2] => Feb 2017
)
I am trying to merging this arrays so I can get below result,
but it's not happening. In this array, I using array_search() and in_array() for checking the array values is present in result array but not getting expected result. I want below output,
Array
(
[Dec 2016] => 2
[Jan 2017] => 0
[Feb 2017] => 2
)
My code:
foreach ( $result_array as $val ) {
$month = array_search ( $val ['month'], $monthArray );
if ($val ['count'] == '' || $val ['count'] == 'NULL') {
$countValue = 0;
} else {
$countValue = $val ['count'];
}
$final_array [] = $countValue;
}