+

PHP defined () function

Syntax:
bool defined ($constant_name);
Parameter:this the function takes one parameter as above and described below.
  • $constant_name : This parameter is required. Specifies the name of the constant.
Return Value:This function returns TRUE if the constant exists and FALSE otherwise.Note:This function is available for PHP 4.0.0 and later.Below are examples to illustrate the function:Example 1: < td class = "code"> define ( "constant_key" , "value for the constant key" ); echo defined ( "constant_key" ); ?> Output:
1
Example 2:an if test after defining a constant. define ( "constant_key" , "value for the constant key" ); if (defined ( "constant_key" )) { echo "constant_key is defined" ; } else { echo "constant_key is not defined" ; }
?>
Output:
constant_key is defined
Example 3:check with an if condition without defining a constant.
// define (& quot; constant_key & quot ;, & quot; constant key value & quot;); if (defined ( " constant_key " )) { echo "constant_key is defined" ; } else { echo "constant_key is not defined" ; }
?>
Output:
constant_key is not defined
< / figure>
Get Solution for free from DataCamp guru