Constants in PHP With Example

Constants in PHP With Example. Using this program we print the constant with case-sensitive letters in PHP. A constant is a term that identifies a single value. During the script, the value cannot be altered. A valid constant name begins with a letter or underscores and does not include the $ sign.

<?php
define("information", "Welcome to inlarn.com");
echo information;
?>

 

Output:

Welcome to inlarn.com

Case Sensitive in PHP

Variable and constant names in PHP are case sensitive, although function names aren’t. PHP is the only language that I am aware of that does this. All of the other languages I’ve tried are either case insensitive or case sensitive. Although class and function/method names are case-insensitive in PHP, it is best practise to use them exactly as they appear in their declaration.

define in PHP

A constant is defined with the define() function. Constants are similar to variables, with the following exceptions: The value of a constant cannot be modified once it has been set. A leading dollar symbol ($) is not required for constant names. Regardless of scope, constants can be accessed.