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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
array ( 0 => 1, 1 => 2, 2 => 3, 3 => 6, 4 => 10, )

preferences:
113.22 ms | 407 KiB | 5 Q