3v4l.org

run code in 300+ PHP versions simultaneously
<?php $subset = [1,2,3]; $array = [2,1,5]; var_dump(array_intersect($subset, $array)); $patched = array_intersect($array, $subset); sort($patched); sort($subset); var_dump($array); var_dump($subset); var_dump($patched);
Output for 7.2.0, 7.3.24 - 7.3.33, 7.4.12 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.23, 8.3.0 - 8.3.11
array(2) { [0]=> int(1) [1]=> int(2) } array(3) { [0]=> int(2) [1]=> int(1) [2]=> int(5) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(2) { [0]=> int(1) [1]=> int(2) }

preferences:
80.74 ms | 407 KiB | 5 Q