PHP Tutorial – Basic PHP variables
Hello Friends ,
PHP variables are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive, so $a is different from $A.
A variable name should start with a letter or underscore, followed by any charactor. A variable name starts with number is not a valid variable.
Example :
<?php
$a = “Hi”; // valid
$a_b-987 = “Hello”; // valid
$987abc = “Wrong”; // invalid bcaz variable name starts with number
?>
Variable Scope :
The scope of a variable is the context within which it is defined. Basically you can not access a variable which is defined in different scope.
Look at below example.
<?php
$a = 1; // $a is a global variablefunction hi()
{
echo $a; // try to print $a, but $a is not defined here
}hi();
?>
If you want to use $a variable in hi() function than you have to use ‘global’ keyword. Look at below example.
<?php
$a = 1;
$b = 2;function add()
{
global $a, $b; // now $a and $b are available in add()
$a = $a + $b;
}add();
echo $a;
?>
PHP Superglobals variables :
Superglobals are variables that available anywhere in the program code. They are :
1 . $_SERVER
2 . $_GET
3 . $_POST
4 . $_COOKIE
5 . $_FILES
6 . $_ENV
7 . $_REQUEST
8 . $GLOBALS
Cheers !!
No related posts.
| Print article | This entry was posted by Rakshit Patel on March 18, 2009 at 3:55 am, and is filed under PHP, Programming. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

I am
I am Shail Patel studing in MCA and working as PHP developer(Part time) in ahmedabad. I was looking forward to share my internet ideas to people of this beautiful world. I found this site as an ideal one to do this. Now i am author of this site and i hope my articles will be helpful to you guys.