PHP – Variables

Creating (Declaring) PHP Variables

Variables in PHP plays an important role in storing information and print the values whenever needed in the PHP program. Following are the few important things which you should know about the PHP variables:

  • In PHP, all the variables are represented by a dollar sign ($).
  • Values are assigned in any PHP variable using the Assignment Operators ( = )
  • All the variable names in PHP are case-sensitive.
  • In PHP, a valid variable name starts with a letter or underscore, followed by any number of numbers, letters, or underscores (A-z, 0-9, and _ ).
  • Variables are used to store a number or a string of characters.

Example with PHP variables

Data Types in PHP

There are mainly eight data types in PHP and different data types can store different things. The list of all the data types is given below:

Integers : Integers are whole numbers and there will be no decimal points, like 99 etc.

Integers Example

Doubles : Doubles are floating-point numbers with decimal points, like 99.9 or 99.99 etc.

Strings : A strings is a combination of characters, like ‘PHP is used mainly for web development purpose.’

We can use two types of strings:
1. Single Quoted String – Using single quoted string all the values will be printed as you write instead
2. Double Quoted String – In double quoted string, all the PHP variables values will be replaced with the variable assigned values. So in doubled quoted string we can use PHP variables also to print dynamic values.

Strings Example


Booleans : Booleans can store only two values either it could be true or false.

Booleans Example

Arrays : Arrays can store multiple values in one variable. Arrays could be single dimentional or multi-dimentional.

Arrays Example


Objects : Objects are defined by the programmer using classes, which can be used with other functions within the same class.

Objects Example


Resources : Resources are used to hold references to resources external to PHP (like database connections etc).

NULL : NULL is a special data type whic can hold only one value: NULL.


Leave a Reply

Your email address will not be published.