CodeIgniter Forums
Array in .env file - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Array in .env file (/showthread.php?tid=75164)

Array in .env file - rich8374 - 01-03-2020

I was hoping from the docs here: Treating Environment Variables as Arrays that I could access something in the .env file that used dot syntax as an array but it doesn't seem to work.[url=][/url]
Here is an example, after copying the env file to .env and uncommenting the database.default section:

PHP Code:
$database getenv('database');

$database just contains boolean false.

Is it possible to access everything prefixed with e.g. 'database' as an array?

RE: Array in .env file - InsiteFX - 01-03-2020

It will not work because it does not have a namespace or class.

RE: Array in .env file - rich8374 - 01-03-2020

thanks but actually I think my fault was using the getenv command.

The following works:

PHP Code:
$database config('Database');

and shows that database.default is an array