F
F
Fuckingawesomenigga2019-04-09 13:57:16
PHP
Fuckingawesomenigga, 2019-04-09 13:57:16

How to check for the presence of directories and remove the missing ones from the array?

Hello, the structure is as follows:
/index.php - among other things, controls the redirect to the desired localization
/langs.php - contains an array with all languages

<?PHP
return array(
  array(
    'name'		=> 'Russia',
    'sysname'	=> 'ru',
  ),
  array(
    'name'		=> 'Germany',
    'sysname'	=> 'de',
  ),
  array(
    'name'		=> 'European-union',
    'sysname'	=> 'en',
  ),
  array(
    'name'		=> 'Australia',
    'sysname'	=> 'au',
  ),
);

/langs/en, ru, de - the folder contains existing localizations
. The next idea is to the index file, the langs array gets there, then it is necessary by 'sysname', check for the presence of directories and overwrite the array with only the existing ones.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
fuckingawesomenigga, 2019-04-09
@fuckingawesomenigga

foreach ($langs as $key => $value) {
  if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/lib/langs/'. $value['sysname'] .'/index.php')) {
  }else{
    unset($langs[$key]);
  };
};

I
irishmann, 2019-04-09
@irishmann

file_exists

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question