defined() function in PHP



The defined() function in PHP checks that constant exists or not.

Syntax

defined(name)

Parameters

  • name− The name of constant.

Return

The defined() function returns true if the constant exists otherwise false.

Example

The following is an example that checks whether a constant exist.

 Live Demo

<?php
   define("myConstant","This is it!");
   echo defined("myConstant");
?>

Output

The following is the output.

1

Advertisements