I have a function that I am trying to run but it shows the message as CONSTANT already defined.
I tried to put a condition saying "if defined" about the function but still nothing. Is there any method to ignore this and see the output?
A PHP constant is the opposite of a variable in that once it has been defined it cannot be changed. Constants are particularly useful for defining a value that you frequently need to refer to that does not ever change.
PHP constants are name or identifier that can't be changed during the execution of the script except for magic constants, which are not really constants. PHP constants can be defined by 2 ways: Using define() function. Using const keyword.
Yes, You can define an array as constant. From PHP 5.6 onwards, it is possible to define a constant as a scalar expression, and it is also possible to define an array constant. It is possible to define constants as a resource, but it should be avoided, as it can cause unexpected results.
Replace this:
define('constant', 'value');
with this:
if (!defined('constant')) define('constant', 'value');
define()
Example:
/* Note the use of quotes, this is important. This example is checking * if the string 'TEST' is the name of a constant named TEST */ if (defined('TEST')) { echo TEST; }
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