How to make constant in php - After we learn about variables and data types, we now learn about the constants in php. Constants are constant variables whose value is unchanged. To define constants in PHP, use the define() function.
In the programming language, Constants (constant) are a storage location (in memory) that contains values that are fixed and irreversible throughout the program.
Unlike variables whose content can be changed and even deleted during the program, a constant if it has been assigned a value, can not be changed in program code. This is seseuai with its name, ie konstant.
File Name: Constants.php
Description: Program use of constants in PHP.
In order to understand more about the constant in php, here I include the example of a constant program in php.
How to Make Constant in PHP
Please open notepad then type the following php code into notepad.
<?php
define ("NAME", "Milka Setiani");
define ("VALUE", 90);
//NAME = "Johans"; //Will cause an error
echo "Name : " . NAME;
echo "<br>Value : " . VALUE;
?>
If you type the code, then next save the code in the htdocs folder.
To see what the program looks like, please open the browser then in the adress bar type http://localhost/constants.php then the results will look like the following.
That's a brief explanation from us about how to make constant in php. Hopefully this article I share will help you. Please read and then practiced in order to better understand about the php programming language. Many of my thanks for your attention.
In the programming language, Constants (constant) are a storage location (in memory) that contains values that are fixed and irreversible throughout the program.
Unlike variables whose content can be changed and even deleted during the program, a constant if it has been assigned a value, can not be changed in program code. This is seseuai with its name, ie konstant.
File Name: Constants.php
Description: Program use of constants in PHP.
In order to understand more about the constant in php, here I include the example of a constant program in php.
How to Make Constant in PHP
Please open notepad then type the following php code into notepad.
<?php
define ("NAME", "Milka Setiani");
define ("VALUE", 90);
//NAME = "Johans"; //Will cause an error
echo "Name : " . NAME;
echo "<br>Value : " . VALUE;
?>
If you type the code, then next save the code in the htdocs folder.
To see what the program looks like, please open the browser then in the adress bar type http://localhost/constants.php then the results will look like the following.
![]() |
Program View |
That's a brief explanation from us about how to make constant in php. Hopefully this article I share will help you. Please read and then practiced in order to better understand about the php programming language. Many of my thanks for your attention.
Comments
Post a Comment