Reputation: 23130
Is it possible to create an array with a settings file?
In the index.php
file there it reads .ini
file:
// Parse config file
$settings = parse_ini_file("settings");
E.g. Settings file looks like this:
[States]
east = "Michigan, New York, Minnesota"
Looking to create an array like so:
array('Michigan', 'New York', 'Minnesota')
Upvotes: 13
Views: 20463
Reputation: 102784
The right way to create an array in your ini file is with brackets:
[States]
east[] = Michigan
east[] = New York
east[] = Minnesota
You can see an example in the documentation for parse_ini_file()
:
Upvotes: 56
Reputation: 11132
It returns an associative array. Then, to parse the east states into an array, you could do:
$eastStates = explode(', ', $ini['States']['east']);
if your data is indeed in the format you described. Note that you can create true arrays in ini format, see the documentation.
Upvotes: 4