This article mainly introduces PHP to get array representation of the path, combined with instance form to compare the implementation of the array to the string, the need for friends can refer to the following
In this paper, we describe the path method of getting array representation in PHP. Share to everyone for your reference, as follows:
Problem:
A path is found to be stored as an array in the file parsing process, and the full path is now required to be output as a string
Workaround:
$hostspath =array (' Windows ', ' System32 ', ' drivers ', ' etc ', ' hosts '); $pathstr = '; foreach ($hostspath as $k = = $v) {$ pathstr.= $v. '/';} $pathstr =substr ($pathstr, 0,-1); Echo $pathstr;
Output:
Windows/system32/drivers/etc/hosts
After writing the above code, think of this as an array to string problem, you can also use a more simple Method!
Improved method:
$hostspath =array (' Windows ', ' System32 ', ' drivers ', ' etc ', ' hosts '), $pathstr =implode ('/', $hostspath); Echo $pathstr;
The output results are also:
Windows/system32/drivers/etc/hosts
Summarize:
Using PHP's own system functions to solve the problem is often more simple and efficient than the algorithm you come up with!