0

the directory structure is like this

modules/
       /module1
              /messages/
                       /en
                          /admin.php
                          /profile.php
                       /ru/
                          /admin.php
                          /profile.php

       /module2/
              /messages/
                       /en
                          /account.php
                          /stats.php
                       /ru
                          /account.php
                          /stats.php

each of thos php files has a huge array inside where by the array contains a key value pair of the text strings like e.g

return array(
'hello' => 'aloha'
);

so how to get the arrays in each files ?

sasori
  • 5,249
  • 16
  • 86
  • 138

1 Answers1

-1

you may implement new method to achieve this using glob() php function

$language = 'en';

foreach (glob('modules/*/messages/' . $language . '/*') as $file) {
    echo "$file\n";
}

Output :

modules/module1/messages/en/admin.php
modules/module1/messages/en/profile.php
modules/module2/messages/en/admin.php
modules/module2/messages/en/profile.php

to return arrays from inside those files :

$language = 'en';
$arrays = [];
foreach (glob('modules/*/messages/' . $language . '/*') as $file) {
    $arrays[] = require_once "$file";
}

print_r($arrays);
hassan
  • 7,812
  • 2
  • 25
  • 36
  • then how you get the arrays from each of those files ? – sasori Apr 03 '17 at 08:25
  • is there a way also to get the e.g en, ru, ch, jp ..because those abbreviations are names of directories inside the messages directory...i want to know also how many languages are available inside the messages directory – sasori Apr 03 '17 at 08:30
  • you need to get count of en,ru,ch.... ? or need to generally get your all data from all messages dirs ? – hassan Apr 03 '17 at 08:33
  • basically i just need to get all the messages of each languages – sasori Apr 03 '17 at 08:35
  • use this pattern inside glob instead `'modules/*/messages/*/*'` – hassan Apr 03 '17 at 08:36
  • when you assigned the $file the empty array,it's not reading the actual arrays inside each files right?..you just assigned the file names – sasori Apr 03 '17 at 08:43
  • you need to return your arrays from your languages files , in the latest example I've included the files using `require_once` – hassan Apr 03 '17 at 08:53