Home Php PHP Working with Variables Tutorial

 
 

Share on Google+Share on Google+

PHP Working with Variables Tutorial

Advertisement
Variables are one of the most important concepts of PHP, learn how to use them here.

PHP  variables

     

If you are planning to start writing in PHP you should  know what a variable is and how to use a variable..
Here is an example of a variable: $jim = "cricket";
What is a variable exactly? A variable is much like a container which can contain String, Integer, Float, Character or Boolean value.

All variables begin with the $ symbol followed immediately by a word which is known as the variables name. No characters or symbols are allowed inside the variables name other then NUMBERS, LETTERS, AND UNDERSCORE SYMBOL (an underscore is this: _ ).
Here is an example of proper syntax
This name would not be allowed: $stea7th owns
This one would though: $stea7th_owns
You must remember though that all variable names are case sensitive, so that means $stea7th and $STEA7TH are not the same. In PHP it is not required to declare any variable before we use it. PHP is loosely typed language, PHP depends on the  value not on the variable, it automagically converts a variable to different datatypes.

Some examples of variable declaration and use are given below:

Example 1:

<?php

$var="This is String value";

echo "<b>Value of \$var is $var</b><br/>";

echo "<b>Datatype of variables are dynamic in nature</b><br/>";

$var=121;

echo "<b>Value of \$var is $var</b><br/>";

?>

Output:

Value of $var is: This is String value
Datatype of variables are dynamic in nature
Value of $var is: 121

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 12, 2009

Related Tutorials

Discuss: PHP Working with Variables Tutorial  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Narsing Rao
July 29, 2011
Connection parameters

I am devoloped a website and it is running proparly in the internet but when i am trying to run that code on Wamp server Output is showing but it is connecting to database. Any one help to what are the connection parameters to connect with the database in PHP Thank you
DMCA.com