Create a constant and print its value:
<?php
const MY_CONSTANT = 5;
echo MY_CONSTANT;
?>
Try it Yourself »
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.
Read more about constants in our PHP Constants Tutorial.
Create a constant and print its value:
<?php
class MyClass {
const MY_CONSTANT = 5;
}
echo MyClass::MY_CONSTANT;
?>
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!