PHP VARIABLES


php tutorial

PHP DATA TYPES

php tutorial

In programming if we want to use values then we have to use data type to represent it’s base type as real, integer, character or Boolean that determines the possible values for that type. We can perform action on values of that type. The meaning of data, and way values of that can be stored.

PHP support eight primitive data types.
Four primitive types
  1. boolean
  2. integer
  3. float
  4. string
Two compound types
  1. Array
  2. Obejct
finally two special types
  1. resource
  2. NULL

VARIABLE

Variable is a temporary storage area to storing value given by user or program. variable's type depend on data types followed by programming language. In PHP $ sign represent variable to storing value and work with it.

Example:

	<?php
						
		$a=100;
						
		echo $a;
						
	?>

In PHP using any variable we don't need to declaration of it, because in PHP variable get the data-type when we assign any value. In above example integer variable automatically defined after getting same type value.

Naming conventions for PHP variables


There are the following rules for naming a PHP variable:

  1. All Variables in PHP start with a $ sign, followed by the name of variable.
  2. A variable name must start with a letter or the underscore character "_".
  3. A variable name can not start with number.
  4. A variable name in PHP can only contain alpha-numeric characters and underscores (A-z, 0-9).
  5. A variable name can not contain spaces.
  6. Note: $ sign must be first character in declaring name of variable using PHP.
     

    Note:Variables in PHP are case sensitive so be careful when using $x or $X both are not same name of a variable.