3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function v1($first, $last) { $result = trim($first); $lastName = trim($last); if ($lastName) { if (!empty($result)) { $result .= ' '; } $result .= $lastName; } return $result; } function v2($first, $last) { return implode(" ", [trim($first), trim($last)]); } function v3($str1, $str2) { return (strlen($str1) > 0 && strlen($str2) > 0) ? ($str1 + " " + $str2) : (strlen($str1) > 0) ? $str1 : $str2 ; } function v($first, $last) { echo v1($first, $last); echo PHP_EOL; echo v2($first, $last); echo PHP_EOL; echo v3($first, $last); } v('first', 'second');
based on G7TjL
Output for 7.1.0 - 7.2.0
first second first second Warning: A non-numeric value encountered in /in/6nJem on line 24 Warning: A non-numeric value encountered in /in/6nJem on line 24 Warning: A non-numeric value encountered in /in/6nJem on line 24 second
Output for 5.4.0 - 7.0.20
first second first second second
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/6nJem on line 19
Process exited with code 255.