Variables – DataTypes & Expressions In PHP


  • A variable is a named memory location.
  • A variable stores different types of data
  • A variable contains data that keep on changing during execution.

An expression is a combination of:

  • Variables
  • Constants
  • Functions
  • Operators


Are names given to various elements of a program such as variables, constants, arrays, functions, and classes

Rules to be followed while naming identifiers are as follows:

  • It must begin with a letter
  • It must contain only letters (A to Z) or digits (0-9)
  • It must not have any special characters including blank space
  • An underscore (_) character can be used to add space in the identifier to make it more readable
  • Valid identifiers names are firstnum, lname, net_sal, add8num, and NewNum


  • Variable is an identifier whose value keeps changing throughout the execution of a program
  • Variable has:
    • Name – refers to the variable
    • Data type – refers to the type of data that the variable can store
  • Variables are used to store:
    • User information
    • Intermediate data such as calculated results
    • Values returned by the functions

Rules to be followed for a variable are as follows

  • A variable is of the same data type as the value stored in it
  • Variable name is preceded by a dollar sign ($) and can only contain alpha-numeric characters and underscores
  • Value to the variable is assigned with the equal to (=) operator, with the variable on the left side and the expression on the right side
  • A variable created without any value assigned to it, takes the default value of NULL
  • A variable is case-sensitive

PHP supports primitive data types that are categorized as follows:

  • Scalar Types
    • Integer
    • Float
    • String
    • Boolean
  • Compound Types
    • Array
    • Object
  • Special Types
    • Resource
    • Null
  • Constants

PHP is a Loosely Typed Language

  • PHP automatically converts the variable to the correct data type, depending on its value.
  • In other languages such as C, C++, and Java, the programmer must declare the name and type of the variable before using it.

Click Below Link to Download Notes Of This Blog

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *