3v4l.org

run code in 300+ PHP versions simultaneously
<?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, 'count', 'yearmonth'); foreach ($dates as &$date) { $date['count'] = $lookup[$date['yearmonth']] ?? 0; } var_export($dates);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
array ( 0 => array ( 'yearmonth' => '2019-6', 'count' => 0, ), 1 => array ( 'yearmonth' => '2019-7', 'count' => 3, ), 2 => array ( 'yearmonth' => '2019-8', 'count' => 0, ), 3 => array ( 'yearmonth' => '2019-9', 'count' => 3, ), 4 => array ( 'yearmonth' => '2019-10', 'count' => 5, ), )

preferences:
131.76 ms | 408 KiB | 5 Q