All PHP Variables


Variable is an identifier used to store value. It can be changed or removed at any time. The variable name should start with a $ sign. The syntax is,

While declaring a variable we need not specify its data type. In PHP, the data type of its value is taken as the variable type. For example,

In this example code snippet, the $message is string variable whereas $count is int, based on the value.

Types of variables

In PHP there is various type of variables. This categorization is based on the scope of the variable.

  • Global variables – These variables have global scope and visibility to access from anywhere. For accessing them in separate file, class or function we have to use global keyword. For example global $global_variable_name.
  • Local variables – The variables that are defined and used within some specific function or any other program block are called as a local variable.
  • Superglobals – These are predefined global variables. For example, $_GET, $_SERVER and etc. It can be accessed from anywhere without the global keyword.

Leave A Reply

Your email address will not be published.