PHP program to check a constant is defined or not

Here, we are going to learn how to check a constant is defined or not in PHP?
Submitted by Nidhi, on November 11, 2020

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.

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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.