Converting a string to a defined constant in PHP

11,626

Use constant function

echo constant("ERROR_0");
Share:
11,626

Related videos on Youtube

Deets McGeets
Author by

Deets McGeets

Updated on October 13, 2020

Comments

  • Deets McGeets
    Deets McGeets over 3 years

    Let's say I have defined the constant ERROR_0 as follows:

    define("ERROR_0","An error occurred.")
    

    Now, let's say I have the string "ERROR_0" but I want to convert that into the constant ERROR_0 such that I can get the string "An Error occurred." How can I do that?

    Thanks!

    • xdazz
      xdazz over 12 years
      The function is constant.