3v4l.org

run code in 300+ PHP versions simultaneously
<?php function joinPath() { $path = ''; $arguments = func_get_args(); $args = array(); foreach($arguments as $a) if($a !== '') $args[] = $a;//Removes the empty elements $arg_count = count($args); for($i=0; $i<$arg_count; $i++) { $folder = $args[$i]; if($i != 0 and $folder[0] == DIRECTORY_SEPARATOR) $folder = substr($folder,1); //Remove the first char if it is a '/' - and its not in the first argument if($i != $arg_count-1 and substr($folder,-1) == DIRECTORY_SEPARATOR) $folder = substr($folder,0,-1); //Remove the last char - if its not in the last argument $path .= $folder; if($i != $arg_count-1) $path .= DIRECTORY_SEPARATOR; //Add the '/' if its not the last element. } return $path; } print(joinPath("blah", "dsdf", "gda"));
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
blah/dsdf/gda

preferences:
237.62 ms | 405 KiB | 374 Q