PHP constant is a name or an identifier for a simple value that cannot change during the execution of the script.
A valid constant name starts with a letter or underscore $ sign can not use before constant define.
Constants are case-sensitive by default.
PHP constants are defined using the define() function. Here's the basic syntax:
define(name, value, case-insensitive);
- name: The name of the constant.
- value: The value of the constant.
- case-insensitive (optional): Indicates whether the constant name should be case-insensitive. Default is false.
Here's an example of defining and using a constant:
<?php
define("PI", 3.14);
echo "The value of PI is " . PI;
?>
In this example-
The constant PI is defined with a value of 3.14. Once defined, you can use the constant in your code by referencing its name (in this case, PI).