<?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.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.16, 8.4.1 - 8.4.2
- 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:
139.29 ms | 407 KiB | 5 Q