PHP Variable ~ PinoySourceCode

Friday, April 25, 2014

PHP Variable

Variable is just like a container for data. In PHP, there are two type of variable. Predefine variable(SuperGlobal Variable) and User define Variable.

SuperGlobal Variable
 This is predefine variable and these variables are automatically available to any PHP program.  There is no need to declare and define these variable in the program.And this re the example of superglobal variable

$_GET
$_POST
$_COOKIE
$_SESSION
$_FILES
$_ENV
$_REQUEST
$_SERVER

2. Define Variable
 This variable is declare and define

Example:
$x=34;
$x is a variable and the value of $x is 34 and 34 is a data and this data store in variable $x.
Code to print value of $x

echo $x;

here the echo statement print variable data.
===================
output
30
===================
another statement to print the value of $x:
echo "Number is $x";

output
===================
30
===================

Exercise 1:
<?php
$x=60;
echo $x;
?>
Output
===================
60
===================
Exercise 2:
<?php
$x=20;
echo "Number is $x";
?>
Output
===================
Number is 20
===================


Exercise 3:
<?php
$x=10;
$y=20;
$ans=$x+$y;
echo "Answer is $ans";
?>
Output
===================

Answer is 30
===================

0 (mga) komento:

Post a Comment

Get updates

Twitter Facebook Google Plus LinkedIn RSS Feed Email

Get Free Updates in Your Email


Enter your email address:

Popular Posts