Q:

PHP program to check a constant is defined or not

belongs to collection: PHP Classes & Objects Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

<?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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Classes & Objects Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP program to print the line number using __LINE_... >>
<< PHP program to create a case in-sensitive constant...