PHP constants are name or identifier that can't be changed during the execution of the script.
PHP constants can be defined by 2 ways:
- Using define() function
- Using const keyword
PHP constants follow the same PHP variable rules. For example, it can be started with letter or underscore only.
Conventionally, PHP constants should be defined in uppercase letters.
PHP constant: define()
Let's see the syntax of define() function in PHP.
define(name, value, case-insensitive)
- name: specifies the constant name
- value: specifies the constant value
- case-insensitive: Default value is false. It means it is case sensitive by default.
- Let's see the example to define PHP constant using define().
<?php define("MESSAGE","Hello w3professors"); echo MESSAGE; ?>