Constant is used for data that is unchanged at multiple places within our program. In this tutorial, we will learn how to create constants.
Constants in PHP:
Creating a PHP Constant:
By using define() function, you can create a constants which accept two arguments: The name of the constant and its value.
In the above example, the constants are defined as a key-value pair. The key is used to get the value of the constant.
In this example, the define() function gets only two parameters. The define() function has an three parameter but third is optional to set the case insensitivity of a constants. By default, the constants are case sensitive. We can make them case insensitive by setting the case insensitivity is true. So, the above example can be changed as,
By using constant() function, we will return the value of the constant.
Constants are Global:
Constants are global by default, and it can be used throughout the program, accessible inside and outside of any function.