How do I define a constant in PHP?
And here is how:
<?php
define('NAME', 'Tarquin');
?>
This defines a constant called NAME and assigns it the value of Tarquin. Now assuming you don't ever change your name (well, maybe if you're called Tarquin...) then this would be a possible instance of defining a constant.
How do you access it? Like this:
<?php
echo 'Hello, ' . NAME;
?>
It is very important to note that the constant is printed outside of any quotation marks; include it within them and you will just see NAME printed to screen rather than the actual value of the constant.
Comment on this Question and Answer >>>
ASK A QUESTION
More other PHP Questions
What is the difference between sessions and cookies?What is the differece between $message and $$message?
How can I add branching logic to my PHP code?
What is a constant in PHP?
Can I spellcheck my text using PHP?
