php - how to get fullpath of scandir() -
when scandir() it's return in array this
array( [0]=> string(8) "devtools" [1]=> string(17) "lb-particles.phar" [2]=> string(11) "nogrifersdp" [3]=> string(12) "packetlogger" [4]=> string(24) "pocketmine-devtools.phar" )
so want fullpath of files this
array( [0]=> string(8) "c:\users\username\pocketmine-mp\plugins\devtools" [1]=> string(17) "c:\users\username\pocketmine-mp\plugins\lb-particles.phar" [2]=> string(11) "c:\users\username\pocketmine-mp\plugins\nogrifersdp" [3]=> string(12) "c:\users\username\pocketmine-mp\plugins\packetlogger" [4]=> string(24) "c:\users\username\pocketmine-mp\plugins\pocketmine-devtools.phar" )
the code tried use didnt work
$pluginsfolder = $this->getserver()->getdatapath()."plugins/"; $plugins = array_slice(scandir($pluginsfolder), 2); foreach ($plugins $plugin); $pluginspath = $pluginsfolder . $plugin; var_dump($pluginspath);
you can modify each element reference &
:
foreach($plugins &$plugin) { $plugin = $pluginsfolder . $plugin; }
or key:
foreach($plugins $key => $plugin) { $plugins[$key] = $pluginsfolder . $plugin; }
or without foreach
:
$plugins = array_map(function($plugin) use($pluginsfolder) { return $pluginsfolder.$plugin }, $plugins);
however, glob()
return full path:
$plugins = glob("$pluginsfolder*")
Comments
Post a Comment