note 114579 added to dir.constants
| From: | Anonymous | Date: | Sat, 08 Mar 2014 15:04:34 +0000 |
| Subject: | note 114579 added to dir.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198833@lists.php.net to get a copy of this message | ||
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");
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/dir.constants.php
Edit -- https://master.php.net/note/edit/114579
Del: integrated -- https://master.php.net/note/delete/114579/integrated
Del: useless -- https://master.php.net/note/delete/114579/useless
Del: bad code -- https://master.php.net/note/delete/114579/bad+code
Del: spam -- https://master.php.net/note/delete/114579/spam
Del: non-english -- https://master.php.net/note/delete/114579/non-english
Del: in docs -- https://master.php.net/note/delete/114579/in+docs
Del: other reasons-- https://master.php.net/note/delete/114579
Reject -- https://master.php.net/note/reject/114579
Search -- https://master.php.net/manage/user-notes.php