PHP define()

📔 : PHP 🔗

PHP में define() function का use named constant define करने के लिए किया जाता है।

Understanding Constants

Important
PHP में Constants, Identifier होते हैं जिन्हे हम variables की तरह ही define करते हैं , हालाँकि variables की तरह इनकी value mutable नहीं होती , means हम script के execution के समय इनकी value को change नहीं कर सकते हैं। ( जैसे हम variable को Define करके हम Runtime पर भी increment या decrement करके value change करते हैं। )
Read More About Constant In PHP...


PHP define Syntax

PHP version < 8

define ( string $name , mixed $value , bool $case_insensitive = false );

PHP version >= 8

define ( string $name , mixed $value);

Parameters
  1. string $name | required : यह constant variable का name है।

  2. mixed $value | required : यह define किये जाने वाले constant variable की value है , आप अपनी need के according किसी भी तरह की value pass कर सकते हैं।

    Understanding mixed Type

    mixed type का मतलब होता है , कि आप अपनी need के according किसी भी type (String , Boolean , Array , Class , Numeric) की value pass कर सकते हैं। यह जरूरी नहीं है कि कोई special type की value ही pass करें।

  3. bool $case_insensitive | optional : यह Boolean value होती है जो कि constant case insensitive है या नहीं। true means - constant case insensitive है और false का मतलब constant case sensitive . By Default false set होता है।

    ? case insensitive constant आप PHP 8 से पुराने version में ही define कर सकते हैं , PHP 8 और इसके बाद के PHP version में case insensitive constant define नहीं करते , अगर आप ऐसा करने की कोशिश करते हैं तो कुछ इस तरह से error मिलेगी।

    Warning: define(): Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported

  4. Return Value : successfully constant define होने पर true return होता है otherwise false.

PHP define Example

<?php
    echo define('NAME', 'Rahul Kumar Rajput');
    echo '<br>'. NAME;
?>

Output
1 Rahul Kumar Rajput

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