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!
A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). Note: Unlike variables, constants are automatically global across the entire script.
Answer: Use the strval() Function You can simply use type casting or the strval() function to convert an integer to a string in PHP.
The constant() function returns the value of a constant. Note: This function also works with class constants.
No, you cannot redefine a constant (except with runkit_constant_redefine), that's why is called CONSTANT.
Use constant
function
echo constant("ERROR_0");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With