3v4l.org

run code in 300+ PHP versions simultaneously
<?php $color_ids = [ 'green' => [1, 2, 3], 'blue' => [4, 5], 'red' => [6], 'pink' => [7, 8, 9], 'yellow' => [10] ]; $select = ['green', 'red', 'yellow']; var_export( array_merge( ...array_values( array_intersect_key( $color_ids, array_flip($select) ) ) ) );
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array ( 0 => 1, 1 => 2, 2 => 3, 3 => 6, 4 => 10, )

preferences:
108.85 ms | 1370 KiB | 4 Q