Share on Google+Share on Google+
PHP Variable
Posted on: November 3, 2009 at 12:00 AM
Advertisement
PHP Variable: In this PHP tutorial you will come to know about the basic things of variables and how to print the special symbols like double quote, variable name etc.

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"

 

Advertisement

Related Tags for PHP Variable:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 3, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com