आज हम 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 भी हो सकती हैं.
इनको भी पढ़े
- Introduction of software Engineering in hindi
- HDFS- (Distributed file system) feature and goals (in hindi)
किसी भी variable के दो attribute होते हैं
How to write a variable Name
- variable का नाम meaningful होना चाहिए. जैसे Total कोई variable का नाम हैं इसके नाम से ही पता चल रहा हैं इसमें total value store होंगी.
- php में किसी variable का नाम “$” sign से स्टार्ट होता हैं उसके बाद variable का नाम देना होता हैं. जैसे – “$name”.
- php में variable का name letter तथा underscore “_” से सटार्ट होता हैं.
- आप variable का name किसी number से start नहीं कर सकते हैं तथा php में underscore के बाद भी number use नही कर सकते हैं.
- php में कोई भी variable alpha , numeric तथा underscore का combination होता हैं.
- php में variable case sensitive होते हैं.
-
-
- जैसे – “$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(); ?>
- color CRT (cathode ray tube) monitor kya and ये कैसे color create करता हैं.
- type of big data in hindi | big data के प्रकार हिंदी में
- Characteristics of cloud computing in hindi tutorial