Learning PHP Variable


Learning PHP Variable

Variable are used as the storage file for understanding it easily we can compare variable with container box. You can name the box and can save specific data in each box. For example you have a box name clothes you can fill the box with garments jeans etc. Similarly when you create a variable you can give it a name and store some value in it.
Variables start with $ symbol

PHP Variable naming rules

·         Variable names must start with a letter of the alphabet or the _(underscore) character.
·         Variables names can contain only the characters: a-z,A-Z,0-9, and  _(underscore).
·         Variable names may not contain spaces. Instead of spaces you can use underscore (eg. $my_name).
·         Variable names are case sensitive. $My_name is not same sa variable $my_name.

Example of string variable

<?php
$filename= “learning php”;
echo $filename;
echo “<br/>”;
$current_file = $filename;
echo $current_file;
?>

Example of Numeric Variables

$counter =25;
You can use floating point number with same syntax;
$counter =25.6;

Arrays

Before discussing about variable in arrays I will explain about array. We can understand about array as the boxes attached together in a queue. With the help of array you can call out the attached boxes information individually by calling its number.
Let’s take an example of a group of seo experts. We will put them in an array.

Example of array variable

<?php
$seoexperts = array(‘Rahul Rana’, ‘temp1’,’temp2’,’temp3’,’temp4’);
echo $seoexperts[3]; //displays output temp3



Share on Google Plus

About Rahul Rana

I am an experienced web designer and SEO expert. I am running my own online marketing company i.e "SEO To Web Design". Thanks for reading, keep sharing online marketing and web design knowledge.
    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment

Enter your email address:

Delivered by FeedBurner