3v4l.org

run code in 300+ PHP versions simultaneously
<?php $movies = [ 'MOVIE TITLE #1' => [ 'id' => 11990, 'times' => [ '2023-06-03' => [ '11:00am', '2:30pm', '6:00pm', '9:30pm', ], '2023-06-04' => [ '12:30pm', '4:00pm', '7:30pm', ], '2023-06-06' => [ '12:30pm', '4:00pm', '7:30pm', ], ], ], 'MOVIE TITLE #2' => [ 'id' => 11892, 'times' => [ '2023-06-03' => [ '12:00pm', '3:30pm', '7:00pm', ], ], ], ]; $dates = array_flip(['2023-06-03', '2023-06-04']); $result = []; foreach ($movies as $title => ['times' => $times]) { foreach (array_intersect_key($times, $dates) as $date => $times) { $result[$date][$title] = $times; } } var_export($result);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
array ( '2023-06-03' => array ( 'MOVIE TITLE #1' => array ( 0 => '11:00am', 1 => '2:30pm', 2 => '6:00pm', 3 => '9:30pm', ), 'MOVIE TITLE #2' => array ( 0 => '12:00pm', 1 => '3:30pm', 2 => '7:00pm', ), ), '2023-06-04' => array ( 'MOVIE TITLE #1' => array ( 0 => '12:30pm', 1 => '4:00pm', 2 => '7:30pm', ), ), )

preferences:
308.35 ms | 407 KiB | 5 Q