PHP const Keyword
Example
Create a constant and print its value:
<?php
const MY_CONSTANT = 5;
echo MY_CONSTANT;
?>
Try it Yourself »
Definition and Usage
The const
keyword is used to create constants. Unlike with the define()
function,
constants created using the const
keyword must be declared in the global scope.
Related Pages
Read more about constants in our PHP Constants Tutorial.
More Examples
Example
Create a constant and print its value:
<?php
class MyClass {
const MY_CONSTANT = 5;
}
echo
MyClass::MY_CONSTANT;
?>
Try it Yourself »
❮ PHP Keywords