In PHP 5.6 you can make a variadic function.
<?php
/**
* Builds a file path with the appropriate directory separator.
* @param string $segments,... unlimited number of path segments
* @return string Path
*/
function file_build_path(...$segments) {
return join(DIRECTORY_SEPARATOR, $segments);
}
file_build_path("home", "alice", "Documents", "example.txt");
?>
In earlier PHP versions you can use func_get_args.
<?php
function file_build_path() {
return join(DIRECTORY_SEPARATOR, func_get_args($segments));
}
file_build_path("home", "alice", "Documents", "example.txt");
?>