Variable in php and Variables define rules in hindi

आज हम php के इस आर्टिकल में variable in php and variable define rules in hindi और example के साथ समझंगे की local variable , global variable तथा static variable क्या होते हैं कैसे define करते है with example.

what is variable in hindi

variable किसी भी programming language (जैसे java, .Net, c programming language, c++, php आद ) का fundamental block होता हैं.

Variable को किसी भी प्रोग्रामिंग language में value को store करने के लिए use किया जाता हैं यानी की variable container की तरह होता जिसमे value store की जाती हैं  (integer,string, boolean) को store  कर सकते हैं .तथा  variable को प्रोग्राम में कंही भी as reference और मैनीपुलेशन के लिए   use कर सकते हैं. variable की value change भी हो सकती हैं.

इनको भी पढ़े

किसी भी variable के दो attribute होते हैं

syntax php

How to write a variable Name

  1. variable का नाम meaningful होना चाहिए. जैसे Total कोई variable का नाम हैं इसके नाम से ही पता चल रहा हैं इसमें total  value store होंगी.
  2. php में किसी variable का नाम “$” sign से स्टार्ट होता हैं उसके बाद variable का नाम देना होता हैं. जैसे – “$name”.
  3. php में variable का name letter तथा underscore “_” से सटार्ट होता हैं.
  4. आप variable का name किसी number से start नहीं कर सकते हैं तथा php में underscore के बाद भी number use नही कर सकते हैं.
  5. php में कोई भी variable alpha , numeric तथा underscore का combination होता हैं.
  6. php में variable case sensitive होते हैं.
        1. जैसे – “$name” तथा “$NAME” ये दोनों अलग-अलग हैं 

Write way

  • $firstname
  • $_firstname
  • $first_name
  • $first-name
  • $firstName
  • $firstname99

Wrong way

  • $first name
  • $99firstname
  • $first%name
<?php

$firstname  =  10;
echo  $firstname;

?>

 

php loosely typed language

  • php एक loosely type language हैं जिसमे हमको कोई भी variable को data type देने की requirement नहीं होती हैं. क्योकि php automatically variable को convert करता हैं particular data type के अंदर.
  • other language में जैसे (c, c++ java) आदि में हमको variable के आगे data type define करना होता हैं. क्योकि ये सभी language  strongly typed language होती हैं .

php variable Scope in hindi

  • php में आप variable को script में कंही में declared कर सकते हो.
  • php script में variable को कंही में access कर सकते हो.
  • अगर आप variable को function के अंदर define करते हो वो आपका local variable होता हैं.
  • अगर variable को function के बाहर define करते हो वो GLOBAL variable होता हैं.
  • आप local function में variable को function में define कर सकते हो और प्रोग्राम में उसकी value change नहीं कर सकते हो.
  • function के अंदर आप GLOBAL variable के access नहीं कर सकते हैं.
  • अगर आपको function के अंदर  GLOBAL variable access करना हैं तो आपको variable के आगे GLOBAL लिखना होगा. 

GLOBAL variable    

<?php
$shree = "variable name";
function display()
{
    global $shree;
    echo $shree;
}
display();
?>

 

local variable

एक example देखते की local variable कैसे define करते हैं.

<?php
function display()
{
    $shree = "variable Name";
    echo $shree;
}
display();
?>

Static variable

  • जब function का execution complete हो जाता हैं तब उस variable life ख़त्म हो जाती हैं.
  • अगर हमने कोई variable static define किया हैं तो उस variable की life extant हो जाती हैं. तथा उस variable को script में कंही भी access किया जा सकता हैं. click

 

<?php

function display()
{
    static $a = 2;
    echo $a;
    $a++;
}
display();
?>
इनको भी पढ़े
आशा  करता हूँ  variable define rules in hindi, local variable , global variable तथा static variable आपको  समझ में गया होगा . अगर आपको इससे related कोई question पूछना हैं तो आप comment करके पूछ सकते है . हम आपकी comment का जबाब जरुर देंगे . अगर हमारे द्वारा दी गयी जानकारी अच्छी लगी हो तो हमे comment करके जरुर बताये और आपका हमको कोई सुझाब हो तो उसे भी जरुर बताये . दोस्तों आपसे एक request हैं . आप इस जानकारी को आपने दोस्तों , रेस्तेदारो के साथ जरुर शेयर करे | धन्यबाद
Related Posts

Leave a Comment