3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr1 = [ ['customer_id' => 1, 'Expire' => '2019-05-14', 'paid' => 1], ['customer_id' => 2, 'Expire' => '2019-06-20', 'paid' => 0], ['customer_id' => 2, 'Expire' => '2019-06-21', 'paid' => 1], ]; $arr2 = [ ['id' => 3943, 'customer_id' => 1, 'Expire' => '2019-05-14'], ['id' => 3944, 'customer_id' => 1, 'Expire' => '2019-05-14'], ['id' => 4713, 'customer_id' => 2, 'Expire' => '2019-06-20'], ['id' => 4714, 'customer_id' => 2, 'Expire' => '2019-06-21'] ]; foreach ($arr2 as &$a) { // Find the sub-array of $arr1 that matches this array's date and ID $arr1_match = array_filter($arr1, function($v) use ($a) { return $v['customer_id'] == $a['customer_id'] && $v['Expire'] == $a['Expire']; }); // Get the first element from the result $paid = reset($arr1_match)['paid']; // Append the paid-value to this array (done by reference) $a['paid'] = $paid; } print_r($arr2);

preferences:
26.62 ms | 402 KiB | 5 Q