0
votes

I have a function called plugin_loader(). The job this function does is like this. It's searching trough a folder called 'plugins' using glob(). After that it should remove the unnecessary '../../' from the elements of array that is created. So for that i did foreach loop. But for some reason when i do print_r() to see if i did it correct way its displaying only last file like this: '/assets/plugins/test_plugin1.php'. But i have two files 'helloworld.php' and 'test-plugin1.php'. Why its not removing '../../' from both files instead of one? P.S I did check if both files are detected and they are.

I tried count() to see how much elements are in array and than call while loop within foreach. But that just gave me two of same output.

function Plugin_Loader()
  {
    $scanned_files = glob("../../assets/plugins/*.php");
      foreach ($scanned_files as $file) {
       $file_loc = str_replace('../', ' ', $file);
  print_r($file_loc);
     }
  }
1
initialize the $file_loc as an array - Lublaut
if you don't initialize it as an array, it will be a variable. and a variable can store only one value - Lublaut
$file_loc[] = str_replace('../', ' ', $file); - AbraCadaver
@AbraCadaver that worked thanks. - Stefanos
Thank you all it worked - Stefanos

1 Answers

0
votes

You should initialize $file_loc

function Plugin_Loader()
  {
    $scanned_files = glob("../../assets/plugins/*.php");
      foreach ($scanned_files as $file) {
       $file_loc[] = str_replace('../', ' ', $file);
      print_r($file_loc);
     }
  }