Here, we will check a constant is defined or not using the defined() function. The defined() function returns true if the given constant is defined otherwise it returns false.
The source code to check a constant is defined or not is given below. The given program is compiled and executed successfully.
<?php
//PHP program to check a constant is defined or not.
define(PI,3.14);
if(defined("PI")==true)
print("Constant is defined");
else
print("Constant is not defined");
?>
Output:
Constant is defined
Explanation:
In the above program, we defined a constant PI initialized with 3.14. Then we checked constant PI is defined or not using the defined() method and then print the appropriate message on the webpage.
Program/Source Code:
The source code to check a constant is defined or not is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we defined a constant PI initialized with 3.14. Then we checked constant PI is defined or not using the defined() method and then print the appropriate message on the webpage.
need an explanation for this answer? contact us directly to get an explanation for this answer