PHP Basics

PHP Variable Declaration

Variables are essential in any coding world. It helps to code more efficiently.

Lets see how can we define variables in PHP.

PHP Variable Declaration

In PHP, any variable name should always begin with a dollar sign ($) followed with a name. The name should not contain space.







Note: If you know Java, .Net, C# then you must be aware to define variable name we must use keyword (int, float, double etc.). But in PHP, we do not require any keyword. PHP Engine is designed in a way that it can understand from the assigned value, what type of data it is.

What is a variable?

Variable is like a container. In container we can keep chocolate, biscuits, candies what ever we want. Similarly variable is a memory location, where data value is stored.

So in the above example, $fruit_name=”Apple”

A memory location is named with the name $fruit_name and string value “Apple” stored in it. Similar fashion, rest variables work at the backend.


  1. A variable name must begin with $ sign and should not contain space. No special characters are allowed in the name.
  2. Unlike Java, .Net, In PHP we do not require keyword to define the type of variable.
  3. At the backend, a memory location is named with the variable name and assigned value is stored in it.