Constants
Last updated
What is Constants?
Constants in PHP are fixed values that do not change during the execution of the script. They can be handy for values that need to be reused often like a website's URL, a company's name, or even a hardcoded database connection string. Unlike variables, once a constant is defined, it cannot be undefined or reassigned. Constants are case-sensitive by default but this can be overridden. They are defined using the define() function or the const keyword. For instance, you can create a constant to hold the value of Pi and call it in your script like this:
define("PI", 3.14);
echo PI; // Outputs: 3.14
Free resources to learn Constants
- Official docsConstants
More in stage 4: Conditionals
Constants: common questions
Can I learn Constants in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Constants in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Constants tutorial for beginners?
It is lesson 28 of 120 in the free PHP roadmap, in stage 4, Conditionals. If you are new to PHP, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.