Uses of variables in php
In php program, a variable should be followed by $ sign. Php will be considered a text as variable which is followed by $ sign.
Example :
$var_example
In php, we can use variables without declaring. For example if we want to use variable as text we can use like $text_Var="Wish you a happy new year 2017", $int_Var=546 and so on.
Example Program using variable:
<!DOCTYPE html>
<html>
<body>
<?php
$x=10;
$y=5.5;
$z=$x+$y;
$result_Txt="This is the Output of $x+$y is : ";
echo $result_Txt.$z;
?>
</body>
</html>
Global an local variables:
Global variables example
<!DOCTYPE html>
<html>
<body>
<?php
$x=10; //global variable
function insidefunction()
{
echo "The value of variable $x is in inside a function:".$x;
}
echo "The value of variable $x is in outside:".$x;
?>
</body>
</html>
Output of above program is
The error was showing when run the function, So the global variable not into the function. and also first output in the function is not displayed. So, You can understand global variable is using in outside of the function. It will not affect inside the function values.
local variables
Now we are using the variable $x as local variable. It will affect only inside the function. It will not affect the outside value.
For example
<!DOCTYPE html>
<html>
<body>
<?php
function insidefunction() {
$x = 10; // local variable inside the function
echo "<p>Variable x inside function is: $x</p>";
}
insidefunction();
// using x outside the function will generate an error
echo "<p>Variable x outside function is: $x</p>";
?>
</body>
</html>
Output of above program is:
The error was showing when run the outside output, So you can understand local variable will not affect outside of the function. and also second output in the program is not displayed. So, You can understand local variable is using in inside the function wherever we are using.
Keep continue Reading Our blog to learn php! Thank you.
Please Note:-
We are serving to our blog readers to post ad free for their business development. And educating them to develop their own website.
Please check our free websites and blogs.
I am using php script for my website to post free ads - Please click the link and check it out
http://www.freeadsimple.com
To Learn Basic HTML Please Read the article from http://webdevelopmentstepbystep.blogspot.com
We are serving to our blog readers to post ad free for their business development. And educating them to develop their own website.
Please check our free websites and blogs.
I am using php script for my website to post free ads - Please click the link and check it out
http://www.freeadsimple.com
To Learn Basic HTML Please Read the article from http://webdevelopmentstepbystep.blogspot.com
Interesting post.Thanks a lot for uploading the post.
ReplyDeleteFull Stack Training in Chennai | Certification | Online Training Course | Full Stack Training in Bangalore | Certification | Online Training Course | Full Stack Training in Hyderabad | Certification | Online Training Course | Full Stack Training in Pune | Certification | Online Training Course | Full Stack Training | Certification | Full Stack Online Training Course