Skip to content
Advertisement

Creating central config file with hundreds of defined names

I want to create a central config file, with a few hundred of defined setup configure names, that would be included with something like:

include config_file_name.php

I want to write the php code in the config file as follows:

<?php
function config($name) {
foreach name_text_line,
read each line,
change text line to be the $defined_name,
like:

$text_line_name = other_function ( 'setting_data_name' );

/* the first name section changes as shown below, 
but the = other_function is always the same and the 
'setting_data_name' is also the same code */
} 

text_line_name1
text_line_name2
text_line_name3
text_line_name4
text_line_name5
text_line_name6
text_line_name7
text_line_name8
text_line_name9
and_many_more99
?>

So when the above function is included with include file.php, I want function to all respond as if its the same as the following code:

<?php
$text_line_name1 = other_function ( 'setting_data_name' );
$text_line_name2 = other_function ( 'setting_data_name' );
$text_line_name3 = other_function ( 'setting_data_name' );
$text_line_name4 = other_function ( 'setting_data_name' );
$text_line_name5 = other_function ( 'setting_data_name' );
$text_line_name6 = other_function ( 'setting_data_name' );
$text_line_name7 = other_function ( 'setting_data_name' );
$text_line_name8 = other_function ( 'setting_data_name' );
$text_line_name9 = other_function ( 'setting_data_name' );
$and_many_more99 = other_function ( 'setting_data_name' );
?>

I don’t want the include file to have a lot of extra characters or code, just pretty simple with a little code if needed above or below on other lines, so I can add one name line of a new configuration as needed. Its not a list of peoples names, sorry if that confused anyone.

Advertisement

Answer

The variable name or the: $variable Can all be the same name.

As long as the array name or the: $variable['array_name'] Is different words, then there is no need to make a long list of variables in a config file.

Note, make sure that you don’t have similar keys in your config file

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement