If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
variable किसी memory को दिया गया नाम है जो कि किसी value को Hold करती है या store करती है। मतलब जब हम Variable define कर रहें है तो हम memory में value को store करके उसे नाम दे रहे होते हैं।
PHP में Variables $ sign के साथ define किये जाते हैं , Valid PHP Variables को letter और underscore के साथ define किया जा सकता है।
<?php
$_4site = 'Valid Variable';
// valid; starts with an underscore
echo $_4site."<br>";
$4site = 'Invalid variable';
// invalid; starts with a number
echo $4site;
?>
अगर आप किसी variable को number के साथ start करते हैं तो Error आएगी।
PHP Variables case sensitive होते हैं , this means अगर आप एक ही name के Variables को small और capital letters में define करते हाँ तो दोनों ही Variables different होंगे , और different value hold करेंगे।
Copy<?php
$var = 'rahul';
$Var = 'Rahul';
echo "$var, $Var";
?>
ऊपर दिए गए example में आप देख सकते हैं , कि same name के define किये गए हैं लेकिन दोनों ही variables different value Hold किये हुए हैं।
Note - $this special variable है आप इस variable को कुछ भी assign नहीं कर सकते है , हालांकि तह कहाँ पर use होता है ये हम आगे सीखेंगे।
PHP Variables define करते समय हमें कोई type करने की जरूरत भी नहीं पड़ती है , जैसे कि JAVA या C में कोई variable define करते समय इसका टाइप define करना पड़ता है। आप जिस type की value को assign कराओगे variable उसी type की value को hold कर लेगा।
Example -
<?php
$a = "String";
$b = 'String';
$c = 0;
$d = 2.5;
$e = 'C';
$f = true;
$g = '';
$h = null;
echo var_dump($a)."<br>";
echo var_dump($b)."<br>";
echo var_dump($c)."<br>";
echo var_dump($d)."<br>";
echo var_dump($e)."<br>";
echo var_dump($f)."<br>";
echo var_dump($g)."<br>";
echo var_dump($h)."<br>";
?>
इसके अलावा PHP हमें कुछ predefined variables भी provide करती है जिन्हे Super Global Variables कहते हैं।
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