3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fileArr = [ [ 'fileName' => 'CAR.jpg', 'processId' => 111, 'storyId' => 1 , ], [ 'fileName' => 'CAR2.jpg', 'processId' => 112, 'storyId' => 1 , ] ]; $notes = [ [ 'noteId' => 50, 'note' => 'this is a note', 'processId' => 111, ], [ 'noteId' => 50, 'note' => 'this is a note', 'processId' => 112, ], ]; function addNote(array &$array, array $notes) { $array['notes'] = []; foreach ($notes as $note) { if ($note['processId'] == $array['processId']) { $array['notes'][] = $note; } } return $array; } foreach ($fileArr as &$file) { addNote($file, $notes); } var_dump($file);

preferences:
33.51 ms | 404 KiB | 5 Q