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

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook