PHP Dynamic Constants

This is a way to print out a constant when you need to select the name dynamically.

Haven’t tried it yet, but I am adding because I am sure I will need it in the near future.

$changing_variable = 'foo_bar';
echo constant('FOO_' . strtoupper($changing_variable));

 

One Response to “PHP Dynamic Constants”

  1. seiha.ching says:

    Hello I am a student that studying web programming language. PHP is the most important for me. Because it is open source and good language.If it is free I need it

Leave a Reply