chdir()
函数用于改变当前工作目录
<?php $paths = array('/path/to/dir1', '/path/to/dir2', '/path/to/dir3'); foreach ($paths as $path) { chdir($path); echo "Current working directory changed to: " . getcwd() . PHP_EOL; } ?>
在这个示例中,我们首先定义了一个包含多个路径的数组 $paths
。然后,我们使用 foreach
循环遍历数组中的每个路径,并使用 chdir()
函数将当前工作目录更改为每个路径。最后,我们使用 getcwd()
函数输出当前工作目录。