Variable in PHP in Hindi

variable in php in hindi

PHP variable introduction

php में variables को define करने के लिए ” $ ” symbol का इस्तेमाल होता है| define किये गए varible में किसी values को asign ( मतलब की value को इस created variable में put करना या store करना होता है ) करने के लिए ” = ” symbol का इस्तेमाल होता है|
for example के तोर पर हमने एक city name को variable में store करने के liye $city नाम का वेरिएबल ले सकते है निचे में दिखे variable कैसे create करते है और इस variable में value को कैसे store करते है|

$city // create variable name with $ sign
   
$city = "surat";
// asign surat city name into the $city variable

php में variable name $ sign के साथ ही लिखा जाता है| मतलब की variable name declaration के लिए $ sign का इस्तेमाल होता है
php में variable का name $ sign के साथ start होता है और उसके बाद में variable का name होता है|
variable neme को alpha-numeric character और underscore के साथ लिख सकते है|
variable name की सरुआत letters और underscore के साथ कर सकते है|
variable name की सरुआत number के साथ नहीं कर सकते है|
php में variable name case-sensitive होता है मतलब की $city और $CITY दोनों ही अलग-अलग variable है|
php variable में सभी प्रकार के data type को store करा सकते है जैसे की interger, double, string, array

Types of variables in Hindi

Variable scope में local scope variable को manage करना सरल होता है क्योकि local scope variable perticuler function तक ही सिमित होते है मतलब की local variable को perticuler function में ही access किया जा सकता है||
जब की global variable को script में कही बी access किया जा सकता है और global variable को manage करना थोड़ा सा कठिन होता है क्योकि global variable script के अलग-अलग पार्ट में same task performe करता है|

php में कई प्रकार के variable होते है लेकिन variable को अलग उसके scope के आधार पर किया जाता है|

  1. local variable
  2. Global variable
  3. Static variable

Local variable in Hindi

अगर variable को function के अंदर में लिखा जाता है तो इसका scope इस function के block of code के तक ही सिमित होगा तो इसे हम local variable कह सकते है|| local variable को just function के अंदर में access कर सकते है क्योकि वह variable उस function में create किया होता है||

Example:

<?php

 function test_demo(){
  $txt = "Hello world";

  echo $txt;

 }
 test_demo();

?>

Global variable in Hindi

Glabal scope varibale को function,class के बहार कही बी access कर सकते है| global variable को script में function के बहार यानि के सरुआती में बी define कर सकते है, php global variable को global keyword के साथ defines किया जाता है अगर function में इस्तेमाल करना हो तो उसके लिए के global variable के साथ global keyword होना चाहिये|

Example:

<?php

 $txt = 1;
 function test_demo(){
   global $txt;

   echo $txt++;

 }
  test_demo();

  echo $txt;

?>

Static variable in Hindi

Function complate execute होने के बाद उसके सभी variable delete हो जाते है अगर उस को हम हटाना या delete करना नहीं चाहते और वापस से उसका इस्तेमाल करना चाहते है तो ऐसा करने के लिए हमको variable को static keyword के साथ declared करना होता है| static variable का इस्तेमाल इस लिए किया जाता है क्योकि function complate execute होने के बाद उसके variable delete न हो जाये||

Example:

&lt;?php

 function test_demo(){
  static $txt = 1;
  $txt = 0;
  
  echo $txt;
  $rst = $txt + 5;

 }
 test_demo();

?>

function parameter in hindi

function parameter को function name के बाद parenthis में declared किया जाता है||

<?php

 function test_demo(){
   $txt = $val*5;
   return $txt;
 }
 $rst = test_demo(5);
 echo $rst;

?>

Leave a Comment

Your email address will not be published. Required fields are marked *