Local Variable, Global Variable Use
Sample 1 : Simple Function of Local And Global Variable
This is Big Number: 35This number is less than Big Number : 15
Sample 2 : Rules of Local And Global Variables
- We can not use Local Variables outside the function.
- We can not use Global Variables inside the function Directly.
- We can use Global Variables inside the function by $GLOBALS['Variable'].
- But in $GLOBALS['Variable'], you can contain only one single variable.
- For different Variables you will create separate $GLOBALS['x']
- In $GLOBALS all spellings are Capital
- Variable will be written within single quote.
- As you know; after function completion, local variables will be finished, so you need to keep in mind these rules
Sample 3 : Global Variable Use inside the Function.
What is Your Name And Age?My Name is Samee
And My Age is 22 And my double age will be 44
Tell me your complete bio data?
My Name is Samee, age is 22, and My height is 5.3.
Sample 4 : Local Variable use Out Side the Function.
Sorry! We can not use Local Variable out side the Function in PHP. <html>
<head>
<title>Local and Global Variables Use In Function : 3rd Day Lecture of PHP</title>
</head>
<body>
<h1 align="center">Local Variable, Global Variable Use</h1>
<h2 align="left">Sample 1 : Simple Function of Local And Global Variable</h2>
<?php
$a=5;
$b=10;
function add()
{
$c=15;
$d=20;
echo "This is Big Number: " . ($c+$d);
echo "<br />";
}
add();
echo "This number is less than Big Number : ". ($a+$b);
echo "<br />";
?>
<h2 align="left">Sample 2 : Rules of Local And Global Variables</h2>
<?php
echo
'<ol>
<li>We can not use Local Variables outside the function.</li>
<li>We can not use Global Variables inside the function Directly.</li>
<li>We can use Global Variables inside the function by $GLOBALS[\'Variable\'].
<ul>
<li>But in $GLOBALS[\'Variable\'], you can contain only one single variable.</li>
<li>For different Variables you will create separate $GLOBALS[\'x\']</li>
<li>In $GLOBALS all spellings are Capital</li>
<li>Variable will be written within single quote.</li>
</ul></li>
<li>As you know; after function completion, local variables will be finished, so you need to keep in mind these rules</li>
</ol>' //backslash operator is used to give output of single quote of double quote in double quote.
?>
<h2 align="left">Sample 3 : Global Variable Use inside the Function.</h2>
<?php
$name="Samee";
$age=22;
$hight=5.3;
function msr()
{
echo "<b>What is Your Name And Age?</b> <br />";
echo "My Name is {$GLOBALS['name']}";
echo "<br />";
echo " And My Age is " . $GLOBALS['age'] . " And my double age will be " . ($GLOBALS['age']*2) . "<br />";
}
msr();
echo "<b>Tell me your complete bio data?</b> <br />";
echo "My Name is $name, age is $age, and My height is $height."
?>
<h2 align="left">Sample 4 : Local Variable use Out Side the Function.</h2>
<?php echo "<b>Sorry! We can not use Local Variable out side the Function in PHP.</b>" ?>
</body>
</html>
Post a Comment
Give your reviews about this blog. Leave your comments. what do you think about this post?
Comments Description is given below:
1) I love to read comments, but do not spam.
2) Like this blog and also tweet its posts.
3) You can use some xHTML tags.
4) All Comments are Do Follow, Please try to use blog professionally.
5) Mention Your Name below the comment.
6) You can also suggest for improvement.
7) Do not forget to subscribe Samee Articles blog.
---------------------------------------
Thanks for visiting QWC.Me.
==========================================
For free guidelines contact me on SEO Expert | Samee Ullah Feroz is online there.
==========================================
Best Regards