Variables Scope In Hindi

PHP Variables Scope In Hindi

PHP

PHP Variables Scope In Hindi:- Variables Scope In PHP In Hindi Ke Bare Main Ham Is Post main Types Of Php Variables in Hindi Ko Dekhne Wale Hain |

Variables In PHP in Hindi – PHP Main Data Ko Store Karne Ke Liye Variables Ka Istemal Kiya Jata Hai Or PHP Variables Ek Tarah Ka Containers Hota Hain Jo Data Ko Information Ke Rup Main Store Karte Hain |

Yadi Aapne  HTML Full Course  And CSS Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

PHP Variables Scope In Hindi

PHP Main Variables Ko Create Karne Ke Liye ($ dollar sign) Se Start Karte Hain |

For Example:

<php
  
  // How to Create Variables in PHP
  $name = "Hello"
  echo "Welcome $name ";
  
?>

Upper Diye Gaye Code Main Hamne Ek $name ka Variables Create Kiya Hain Or Usme Hamne String “Hello” World Store Kiya Hain Or Use Fir Echo Function Ki Help Se Print Kiya Hain. Aap Uska Output Bhi Niche Check Kar Sakte Hain |

Output:

Welcome Hello

PHP Main Variables Ko Create Karte Waqt Data Types Batane Ki Jarurat Nhi Hoti Hai Kyoki PHP Main Value Assign Karte Hai Waqt Complier Khud Understand Kar Leta Hain. For Example String, Integer, Float, Etc |

Rules for PHP Variables in Hindi

Variables Ko Create Karne Ke Liye All Programming Language Main Rules Hote Hain Waise Hi Rules PHP Language Main Bhi Hote Hain. In Rules Ko Hamne Niche Ek List Main Understand Kiya Hain |

  • PHP Main variables Ko Start Ya define Karne Ke Liye $(dollar) sign Ka Istemal Kiya Jata Hain |
  • Variable Ko Start Kane ke Liye numbers Ka Istemal Nhi Kiya Ja Sakta Hain|
  • PHP Main variable Ko letters Or underscore character Duvara Hi Start Kiya Ja Sakta Hain Kyoki underscore Ek Character Hota Hain |
  • Jab Bhi variable Ko create Kare To Usme Sirf alpha-numeric character(A-z, 0-9) or underscore(_) Ko Hi contain Kar Sakte Ho|
  • Variable case-sensitive Hote Hain Iska Matlab Ki Letter or letter Dono variable Alag-Alag Hain|

For Example:

<?php
$Demo = "This is Variable String";
$demO = 40;
$dEmo = 50.5;
echo "$Demo And demo Values is $demO And dEmo Values Is $dEmo"; 
?>

Upper Diye Code Main Hamne 3 Types Ke Variables Ka Istemal Kiya Hain Or Unki Value Bhi Alag-Alag Hain |

Output:

This is Variable String And demO Values is 40 And dEmo Values Is 50.5

Read Also : PHP Comments

Variables Scope In PHP In Hindi

PHP Variables Ko Declare Kiya Jata Hain Lekin Variables Ko Kaha Acces Kiya Jaye Use Ham Variables Scope Kahte Hain |

  • 1. Local Variable
  • 2. Global Variable
  • 2. Static Variable

Local Variables

Local Variables functions ke under Hote Hain| Unki visibility sirf function ke under Hoti hain, jab wo function ke bahar Aate hai tab destroy ho Jate hain|

For Example :

<?php
function myTest() {
  $x = 5; // local scope
  echo "Variable x inside function is: $x";
}
myTest();

echo "Variable x outside function is: $x";
?>

Aap Upper Diye Code Ko Dekh Sakte Hain Hamne Isme Ek Function myTest() Create Kiya Or Uske Under Ek Local Scope x Variable Create Kiya Hain Or Use Function Ke Under Hi Print Kar Diya Hain And Fir Use Function Ke Bahar Function myTest() Ko Call Kiya |

Lekin myTest() Function Ke Bahar Hamne Fir Local Scope x Variable Ko Print Kiya Lekin Ye Print Nhi Hoga Ye Error Show Karenga Kyoki Local Variable x Ko Ham Function Ke Bahar Print Nhi Kar Sakte Hain | Iska Niche Output Bhi Dkiya Gaya Hain |

Output:

Variable x inside function is: 5
Notice: Undefined variable: x in C:\xampp\htdocs\index.php on line 8
Variable x outside function is:

Global Variables

Global Variables, Function Ke bahar Hote hai | Unki visibility function Ke under or bahar Hoti Hain. Unka scope pure program par Hota hai |

PHP Main Variable Ko global Banane Ke Liye global Keyword Ka Istemal Kiya Jata Hain|

For Example:

<?php
$x = 5;
$y = 10;

function myTest() {
  global $x, $y;
  $y = $x + $y;
}

myTest();
echo $y; 
?>

Output:

15

Static Variables

Jab Function Main Static Variable Ka Istemal Kiya Jata Hain To, Jab Func() Call Kiya Jata Hain, Tab Usme Jo Variables Hote Hain, Vo Aapni Values Ko Hold Karke Rakhte Hain Ye Variables Destroyed Nhi Hote Hain |

For Example:

<html>
<?php
function myTest() {
  static $x = 0;
  echo $x;
  $x++;
}

myTest(); echo"<br>";
myTest(); echo"<br>";
myTest();
?>

</html>

Output:

0
1
2

Friends Mujhe Umeed Hai Ki Aapko Variables Scope in Hindi Ke Bare Mai 100% Jankari Ho Gayi Hogi | Agar Aapko Learn Karne Main Dikkat Aa Rahi Hai To Aap Mere Se Contact Kar Sakte Hai |

Leave a Reply

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