Variables in PHP

Variables in PHP


Posted in : PHP Posted on : December 31, 2010 at 5:37 PM Comments : [ 0 ]

This section contains the detail about the variables in php.

Variables in PHP

Variable has the same definition in all the programming languages. Their implementation or declaration  or syntax may be different but concept is same for all the languages.

A variable is used for storing value such as text strings, numbers or arrays.

You able to use variable over and over again in your PHP script after declaring it.

Given below example give you a quick look of correct way of declaring PHP variable :

$var_name = value;

Naming Rules

Given below key naming conventions of PHP variable :

  • A variable must have $ sign before its actual name. Example, $first_name.
  • A variable in PHP must start with a letter or underscore "_".
  • A variable in PHP can have only numeric(0-9), letter(a-z, A-Z) or underscore"_".
  • PHP variables are case sensitive. The variables $c_number and $C_number are different variables in PHP.
  • The variable name must not have white spaces between them. You can use underscore "_" to fill them. For example, it shouldn't like this-$first name, it should be-$first_name.

No need of declaring data type in PHP

A PHP variable doesn't need to be declare before before adding a value to it. PHP automatically converts the variable to the correct data type, depending on its value.

In the given below example, you will see that there is no need of mentioning data type before passing value to it.

<?php
$variable_txt="Hello World!";
$variable_num=16;
?>  
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics