3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array("test"=>"1", "test2"=>2, "test3"=>3); $needed = array("test", "test2"); $a = array_filter($a, function ($item) { return in_array($item, $needed); });
Output for 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Warning: Undefined variable $needed in /in/MeMC0 on line 7 Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /in/MeMC0:7 Stack trace: #0 /in/MeMC0(7): in_array('1', NULL) #1 [internal function]: {closure}('1') #2 /in/MeMC0(6): array_filter(Array, Object(Closure)) #3 {main} thrown in /in/MeMC0 on line 7
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Warning: Undefined variable $needed in /in/MeMC0 on line 7 Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /in/MeMC0:7 Stack trace: #0 /in/MeMC0(7): in_array('1', NULL) #1 [internal function]: {closure}('1') #2 /in/MeMC0(8): array_filter(Array, Object(Closure)) #3 {main} thrown in /in/MeMC0 on line 7
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.30, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: needed in /in/MeMC0 on line 7 Warning: in_array() expects parameter 2 to be array, null given in /in/MeMC0 on line 7 Notice: Undefined variable: needed in /in/MeMC0 on line 7 Warning: in_array() expects parameter 2 to be array, null given in /in/MeMC0 on line 7 Notice: Undefined variable: needed in /in/MeMC0 on line 7 Warning: in_array() expects parameter 2 to be array, null given in /in/MeMC0 on line 7
Output for 7.3.32 - 7.3.33
Warning: in_array() expects parameter 2 to be array, null given in /in/MeMC0 on line 7 Warning: in_array() expects parameter 2 to be array, null given in /in/MeMC0 on line 7 Warning: in_array() expects parameter 2 to be array, null given in /in/MeMC0 on line 7

preferences:
199.41 ms | 402 KiB | 272 Q