<?php $saved_royalties = [ [ 'gross_total' => 1.797, 'track_name' => 'Desert Dance', 'transaction_type' => 'S' ], [ 'gross_total' => 0.0678, 'track_name' => 'Memphis City Of Kings', 'transaction_type' => 'AS' ], [ 'gross_total' => 0.023, 'track_name' => 'North African Market', 'transaction_type' => 'MT' ], [ 'gross_total' => 0.1173, 'track_name' => 'The Oracle', 'transaction_type' => 'CL' ] ]; $matching_royalty_rows = [ [ 'gross_total' => 2.435174, 'track_name' => 'Desert Dance', 'transaction_type' => 'S' ], [ 'gross_total' => 0.336815, 'track_name' => 'Memphis City Of Kings', 'transaction_type' => 'AS' ], [ 'gross_total' => 0.214106, 'track_name' => 'The Oracle', 'transaction_type' => 'CL' ] ]; $lookup = array_column($matching_royalty_rows, null, 'track_name'); $combined_rows = []; foreach ($saved_royalties as $row) { if (isset($lookup[$row['track_name']])) { $row = $lookup[$row['track_name']]; } else { $row['gross_total'] = 0; } $combined_rows[] = $row; } var_export($combined_rows);
You have javascript disabled. You will not be able to edit any code.