<?php
$jobs = [
['count' => 3, 'yearmonth' => '2019-7'],
['count' => 3, 'yearmonth' => '2019-9'],
['count' => 5, 'yearmonth' => '2019-10'],
];
$dates = [
['yearmonth' => '2019-6'],
['yearmonth' => '2019-7'],
['yearmonth' => '2019-8'],
['yearmonth' => '2019-9'],
['yearmonth' => '2019-10'],
];
$lookup = array_column($jobs, null, 'yearmonth');
$result = [];
foreach ($dates as $date) {
$result[] = $lookup[$date['yearmonth']] ?? ['count' => 0] + $date;
}
var_export($result);
preferences:
29.29 ms | 405 KiB | 5 Q