3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php //old code function v1($first, $last) { $result = trim($first); $lastName = trim($last); if ($lastName) { if (!empty($result)) { $result .= ' '; } $result .= $lastName; } return $result; } //@Big-Shark function v2($first, $last) { return trim(implode(" ", [$first, $last])); } //@Hunternnm function v3($first, $last) { if(strlen(trim($first)) > 0 && strlen(trim($last)) > 0) { return $first." ".$last; } if(strlen(trim($first)) > 0) { return trim($first); } else { return trim($last); } } //@NelinD function v4($first, $last) { return implode(' ', array_filter([$first, $last], function ($string) { return trim($string); })); } //@NelinD function v5($first, $last) { return trim(trim($first).' '.trim($last)); } //@Big-Shark function v6($first, $last) { return trim($first.' '.$last); } function v($first, $last) { var_dump( v1($first, $last) ); var_dump( v2($first, $last) ); var_dump( v3($first, $last) ); var_dump( v4($first, $last) ); var_dump( v5($first, $last) ); var_dump( v6($first, $last) ); echo PHP_EOL; echo PHP_EOL; } v('first', 'last'); v('first', ''); v('first', ' '); v('', ' в last'); v(' ', ' в last'); v(' ', ' в last');
based on 5gHFq
Output for 5.4.0 - 7.3.1
string(10) "first last" string(10) "first last" string(10) "first last" string(10) "first last" string(10) "first last" string(10) "first last" string(5) "first" string(5) "first" string(5) "first" string(5) "first" string(5) "first" string(5) "first" string(5) "first" string(5) "first" string(5) "first" string(5) "first" string(5) "first" string(5) "first" string(7) "в last" string(7) "в last" string(7) "в last" string(8) " в last" string(7) "в last" string(7) "в last" string(7) "в last" string(7) "в last" string(7) "в last" string(8) " в last" string(7) "в last" string(7) "в last" string(7) "в last" string(7) "в last" string(7) "в last" string(8) " в last" string(7) "в last" string(7) "в last"
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/np1p0 on line 20
Process exited with code 255.