Tags
PHP
Asked 3 years ago
20 May 2021
Views 236
jagdish

jagdish posted

how to check constant is already there or not at php ?

how to check constant is already defined or not at php ?


define("IAMDEFINE",1)

How to check is there already exist costant or not in php ?
sachin

sachin
answered Nov 30 '-1 00:00

PHP has one function named defined() which useful in this condition

the defined() function used in PHP for checking whether constant is exists or not

in your case

define("IAMDEFINE",1);
if(defined("IAMDEFINE")){
    echo "defined";
}

in defined function, we need to pass the constant name as argument, and it check constant already defined or not
it will print defined

defined function return true in above scenario , if it was not defined it will return false


Post Answer