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

A visitor from Abuja viewed 'PinoySourceCode' 2 hrs 7 mins ago
A visitor from Charleston viewed 'Payroll system simple but functional using php ~ P' 2 hrs 50 mins ago
A visitor from Dire dawa viewed 'PinoySourceCode' 1 day 23 hrs ago
A visitor from Chandigarh viewed 'PinoySourceCode' 2 days 3 hrs ago
A visitor from Abuja viewed 'PinoySourceCode' 3 days 22 hrs ago
A visitor from Accra viewed 'PinoySourceCode' 4 days 11 hrs ago
A visitor from Hyderabad viewed 'Payroll system simple but functional using php ~ P' 8 days 23 hrs ago
A visitor from Fianarantsoa viewed 'PinoySourceCode' 9 days ago
A visitor from Kathmandu viewed 'PinoySourceCode' 9 days 7 hrs ago
A visitor from Riviere du rempart viewed 'PinoySourceCode' 9 days 11 hrs ago