0

when i scandir() it's return in array like 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 i want it to get the fullpath of the files like 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 i tried to use but didnt work

$pluginsfolder = $this->getServer()->getDataPath()."plugins/";
$plugins = array_slice(scandir($pluginsfolder), 2);
foreach ($plugins as $plugin);
$pluginspath = $pluginsfolder . $plugin;
var_dump($pluginspath);
R7vmc
  • 3
  • 3

1 Answers1

0

You can modify each element with a reference &:

foreach($plugins as &$plugin) {
    $plugin = $pluginsfolder . $plugin;
}

Or with the key:

foreach($plugins as $key => $plugin) {
    $plugins[$key] = $pluginsfolder . $plugin;
}

Or without the foreach:

$plugins = array_map(function($plugin) use($pluginsfolder) {
                         return $pluginsfolder.$plugin
                     }, $plugins);

However, glob() will return the full path:

$plugins = glob("$pluginsfolder*")
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87