there is a process for fixing the value of a variable that will not change. w" /> there is a process for fixing the value of a variable that will not change. w"/> PHP Variable Concept and Data Type-

PHP Variable Concept and Data Type

Variable Introduction

A variable in php simply indicates that the value of it changes from time to time. That means "when a value is changed according to the direction then it is called variable (there is a process for fixing the value of a variable that will not change. we will discuss it in future in PHP advanced section). Like other programming languages such as Java, C, C++ php has not different syntax for declaring different types of variables. Mainly, the difference of a variable in PHP is indicated by its value.

Variable Writing Process in PHP

PHP has also system for storing several types of values such as int, float, string, boolean like other programming languages. But the process of storing value in php is simple different. A user can easily store all types of value by using same syntax. For declaring variable in php it is need to use dollar($) sign with a word. After that it will be regarded as a variable.

Variable Writing Rules

For writing variable you should keep in mind some rules and regulations. Look below list before writing a variable in PHP.

  1. A variable should not start with numeric numbers(0-9)
  2. Variable should not start with special characters (@,^,&,*,!,_,- etc,)
  3. Variable can be like $data_management, not $data-management.
  4. Numeric value can be used inside or outside word like $value1, $value_2
  5. Variable should start with smaller character for single word (example: $value, $data, $id, $status)
  6. For a variable that is built with two words; it should use small character for first word and capital character for second word(example: $salaryManagement, $dataValue, $shopStatus)

  Let's see some example written value for better clearance; $name is a variable where name is joined with $ sign. We can see some variables from the below list.

  • $name (Indicates a variable for storing character or string type value)
  • $salary (Indicates a variable for storing double or float type value)
  • $identify (Indicates a variable for storing boolean type variable)

    //lets see some variable declared below
    $name = "Ariful Islam"; //Storing string value
    $age = 22; //Storing integer value
    $haveWebsite = true; //Storing boolean value
    $currentTemperature = 29.6; //Storing float value

Go through the below table for knowing writing system of a variable in php

Variable Name Sign Store Example
Name $name Character $name = "John"
Salary $salary float or double type data $salary = 5999.43
Age $personage Integer $personage = 25
Status $status Boolean (true/false) $status = true

  We can see an comparing table where you will find the real difference with other language. We are comparing with Java and C  

PHP Java C JavaScript 
$name="Adam" String name = 'Adam' char ='Adam'  var name = "Adam"
$salary= 12000.554 double salary = 12000.554  double salary = 12000.554 var salary = 12000.554
$salary = 1200.55 float salary = 1200.55  float salary = 1200.55  var salary = 1200.55
$status = true boolean status = true bool status = true var status = true