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

Updated on: 27-Jun-2020

191 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements