Constants in PHP

A constant is an identifier for a value that cannot change during the course of a script. Once a constant has a value, it remains through its execution lifetime. Constants can be user defined, or you can use some of the predefined constants that PHP always has available. Unlike simple variables, constants do not have a dollar sign before their name, and they are usually uppercase to show their difference from a scalar variable. Next, you’ll test the user-defined type.

1. Open a new file in your text editor and open a PHP block:
<?

2. The function used to define a constant is called define(), and it requires the name of the constant and the value you want to give it. Here you define a constant called MYCONSTANT with a value of “This is a test of defining constants.”.

define(“MYCONSTANT”, “This is a test of defining constants.”);

3. Print the value of the constant and then close the PHP block:
echo MYCONSTANT;
?>

About the author

Being the CEO and Founder of ClecoTech International, Mr. Ashish Prajapati is dedicated towards his aim of mentoring young startups into a full-fledged businesses. He is helping startups from America, Europe, India, and various other countries through proper guidance and the use of latest technologies to develop their innovation and ideas into definite realities.

Leave a Reply

Your email address will not be published. Required fields are marked *