Yes, it is possible. Your loop should look like below:
foreach( $environments as $env )
{
if( $current_env == $env )
{
define('DEBUG', ${$env.'_settings'}['debug']);
define('CAKE', ${$env.'_settings'}['cake']);
define('DEATH', ${$env.'_settings'}['death']);
break;
}
}
Notes:
- I've fixed the typo in your array declaration. You were using just
=
instead of=>
. - I've added a
break
inside your loop - otherwise, you'll be trying to re-declare constants and that will cause PHP to output errors - I've changed
=
to==
.=
is the assignment operator. You need to use==
(loose comparison) or===
(strict comparison) instead.