Answer the question
In order to leave comments, you need to log in
How and where is it correct to store a large array?
In general, the essence of the question is this, there is an array key => value from the order of more than 200 cells.
The array stores the current locale.
how and where is it better to store this array? (I think it's better in a file? in what form? *.ini or .txt(serialize array))
what is the best way to use it in terms of optimization? to load it at startup and, if necessary, refer to it or pull it when it is needed? There are about 20 items on the page.
At the moment, I did this *ini like this:
hello_world = 'hello world'
world = 'world'
when the application is loaded,
$array = parse_ini_file($filename);
and the template displays
$array['hello_world'];
is the mechanism correct?
Answer the question
In order to leave comments, you need to log in
See how localization tasks are solved in popular frameworks.
A php file is created containing one array:
$lang = [
'world' => 'мир',
'hello_world' => 'привет мир'
];
I would take it when needed. Can be stored in json. Although what to store it to taste. The main load goes to reading the file.
As Anton B said - do include.
Only in this way:
// file1.php
$config = require_once '/path/to/file2.php';
echo $config['foo']; // bar
// file2.php
return [
'foo' => 'bar',
'bar' => 'baz',
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question