3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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($badPort, &$index) { if(!in_array($item['portName'], $badPorts)) $result[] = $index.":".$item['portName']; return $result; }, array())); var_dump($image3);
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
string(18) "1:Moscow,2:Jupiter" string(18) "1:Moscow,2:Jupiter" Notice: Undefined variable: badPort in /in/P9NHX on line 22 Notice: Undefined variable: badPorts in /in/P9NHX on line 23 Warning: in_array() expects parameter 2 to be array, null given in /in/P9NHX on line 23 Notice: Undefined variable: badPorts in /in/P9NHX on line 23 Warning: in_array() expects parameter 2 to be array, null given in /in/P9NHX on line 23 Notice: Undefined variable: badPorts in /in/P9NHX on line 23 Warning: in_array() expects parameter 2 to be array, null given in /in/P9NHX on line 23 string(31) "0:Day At Sea,0:Moscow,0:Jupiter"
Output for hhvm-3.10.0 - 3.12.0
string(18) "1:Moscow,2:Jupiter" string(18) "1:Moscow,2:Jupiter" Notice: Undefined variable: badPort in /in/P9NHX on line 25 Notice: Undefined variable: badPorts in /in/P9NHX on line 23 Warning: in_array() expects parameter 2 to be an array or collection in /in/P9NHX on line 23 Notice: Undefined variable: badPorts in /in/P9NHX on line 23 Warning: in_array() expects parameter 2 to be an array or collection in /in/P9NHX on line 23 Notice: Undefined variable: badPorts in /in/P9NHX on line 23 Warning: in_array() expects parameter 2 to be an array or collection in /in/P9NHX on line 23 string(31) "0:Day At Sea,0:Moscow,0:Jupiter"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/P9NHX on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/P9NHX on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/P9NHX on line 7
Process exited with code 255.