PHP defined()

📔 : PHP 🔗

defined() function check करता है कि दिया गया constant define किया गया है या नहीं।

defined() function सिर्फ constant की existency check करता है , normal variables के लिए isset() use किया जाता है।

PHP defined Syntax

defined ( string $name );

Parameters

  1. string $name | required : constant name जिसे आपको check करना है।

  2. Return Value : अगर constant define किया गया है तो true return होता है otherwise false .


PHP defined Example

File : php_defined.php

Copy Fullscreen Close Fullscreen
<?php 
    if(defined('NAME'))
       echo 'NAME is defined';
    else
     	echo 'NAME is not defined';

    /*now define it*/
    define('NAME', 'Rahul Kumar Rajput');

    echo "<br />";
    if(defined('NAME'))
       echo 'NAME is defined';
     else
     	echo 'NAME is not defined';
?>
Output
NAME is not defined
NAME is defined

Hey ! I'm Rahul founder of learnhindituts.com. Working in IT industry more than 4.5 years. I love to talk about programming as well as writing technical tutorials and blogs that can help to others .... keep learning :)

Get connected with me - LinkedIn Twitter Instagram Facebook