PHP Variables

Variables are containers to store data. We can add or change or delete data from the variable and use them in our script. Here are some basic rules to create variables.

Declaring variables in PHP

Variable should start with $

$var1='testing'; // correct
var1='testing'; // Wrong - error
_var1='testing'; // wrong -error
5var='testing'; // wrong -error

Variable should contain numbers, alphabet and underscore

$var1='testing'; // correct
$va!3='testing'; // wrong -error
$var^4='testing';// wrong -error

After $ we can't use number it must be alphabet or underscore

$_var1='testing'; // correct
$1var='testing'; // wrong error
$var1='testing'; // correct

Variables are case sensitive

No need to declare variable type before using in PHP

Scope of Variable

The variables declared as global are available throughout the script and variables declared inside functions is know as local variable and are available inside the function only. Read more on scope of the variables in our PHP functions.

All variables are used within the page or within the script present in a page. As you are reading this page some variables are used to display the content of the page. These variables are lost as soon as this page execution is completed at server and downloaded to your browser. So how to pass the data or retain the data across the pages ?

passing the variables from one page to other

.

Be the first to post comment on this article :


Google+

Post Comment This is for short comments only. Use the forum for more discussions.






OPINION POLL

What is the most important factor of a web site
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer