3v4l.org

run code in 300+ PHP versions simultaneously
<?php $itinerary = array (array('portName'=>'Day At Sea'), array('portName'=>'Moscow'), array('portName'=>'Jupiter')); $badPorts = array('At Sea', 'Day At Sea', 'Cruising The Mediterranean Sea'); $image = ''; $arr = array(); array_walk($itinerary, function($item, $index) use($badPorts, &$arr){ if(!in_array($item['portName'], $badPorts)) $arr[] = $index.":".$item['portName']; }); $image .= implode(',', $arr); var_dump($image); $image2 = ''; $arr2 = array(); foreach($itinerary as $index => $item){ if(!in_array($item['portName'], $badPorts)) $arr2[] = $index.":".$item['portName']; } $image2 .= implode(',', $arr2); var_dump($image2); $index = 0; $image3 = implode(',', array_reduce($itinerary, function ($result, $item) use(&$index) { if(!in_array($item['portName'], $badPorts)) $result[] = $index.":".$item['portName']; return $result; }, array())); var_dump($image3);
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
string(18) "1:Moscow,2:Jupiter" string(18) "1:Moscow,2:Jupiter" Warning: Undefined variable $badPorts in /in/pXiNj on line 23 Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /in/pXiNj:23 Stack trace: #0 /in/pXiNj(23): in_array('Day At Sea', NULL) #1 [internal function]: {closure}(Array, Array) #2 /in/pXiNj(22): array_reduce(Array, Object(Closure), Array) #3 {main} thrown in /in/pXiNj on line 23
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
string(18) "1:Moscow,2:Jupiter" string(18) "1:Moscow,2:Jupiter" Warning: Undefined variable $badPorts in /in/pXiNj on line 23 Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /in/pXiNj:23 Stack trace: #0 /in/pXiNj(23): in_array('Day At Sea', NULL) #1 [internal function]: {closure}(Array, Array) #2 /in/pXiNj(25): array_reduce(Array, Object(Closure), Array) #3 {main} thrown in /in/pXiNj on line 23
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
string(18) "1:Moscow,2:Jupiter" string(18) "1:Moscow,2:Jupiter" Notice: Undefined variable: badPorts in /in/pXiNj on line 23 Warning: in_array() expects parameter 2 to be array, null given in /in/pXiNj on line 23 Notice: Undefined variable: badPorts in /in/pXiNj on line 23 Warning: in_array() expects parameter 2 to be array, null given in /in/pXiNj on line 23 Notice: Undefined variable: badPorts in /in/pXiNj on line 23 Warning: in_array() expects parameter 2 to be array, null given in /in/pXiNj on line 23 string(31) "0:Day At Sea,0:Moscow,0:Jupiter"
Output for 7.3.32 - 7.3.33, 7.4.26
string(18) "1:Moscow,2:Jupiter" string(18) "1:Moscow,2:Jupiter" Warning: in_array() expects parameter 2 to be array, null given in /in/pXiNj on line 23 Warning: in_array() expects parameter 2 to be array, null given in /in/pXiNj on line 23 Warning: in_array() expects parameter 2 to be array, null given in /in/pXiNj on line 23 string(31) "0:Day At Sea,0:Moscow,0:Jupiter"
Output for 5.2.3 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/pXiNj on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<br /> <b>Parse error</b>: syntax error, unexpected T_FUNCTION in <b>/in/pXiNj</b> on line <b>7</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
<br /> <b>Parse error</b>: parse error, unexpected T_FUNCTION in <b>/in/pXiNj</b> on line <b>7</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error in <b>/in/pXiNj</b> on line <b>7</b><br />
Process exited with code 255.

preferences:
301.26 ms | 401 KiB | 460 Q