PHP Variables, Special Symbols in PHP
In any language variables are one of the most important thing, in PHP we can declare a variable of any type, any where.
PHP Variable Example 1:
<?php
$var="This is a string value";//declaration as string variable echo "Value of \$var is: ".$var."<br/>"; $var=23232;//declaration as integer variable echo "Value of \$var is: ".$var."<br/>"; $var=23.23;//declaration as float variable echo "Value of \$var is: ".$var."<br/>"; $var=true; echo "Value of \$var is: ".$var."<br/>"; $var='c'; echo "Value of \$var is: ".$var."<br/>";
?>
Output:
Value of $var is: This is a string value Value of $var is: 23232 Value of $var is: 23.23 Value of $var is: 1 Value of $var is: c
From the above example we can easily understand that the datatype of a variable is dynamic in nature. A variable is capable of storing any kind of value right from String, Integer, Float etc.
Sometimes we need to print Double quote, Single quote, Variable names as a statement, in this case we should use \ sign.
Example 2:
<?php
$var="Any Value";//declaration as string variable echo "With '\' sign output is= \$var"."<br/>"; echo "Without '\' sign output is=$var"."<br/>"; echo"\"This text is within double quote\""."<br/>";
?>
Output:
With '\' sign output is= $var Without '\' sign output is= Any Value "This text is within double quote"
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.