I called variables; developers rock sack because just like a rock sack a variable is something that you can put almost anything into it. From Numbers and charachters to Arrays or even logical results. They are called variables because you can change them as easy as you can set them up.

Have you ever heared “You are what you eat”? well in case of variables they are what they store. So there are different kinds of variables here is a list of the most common variables that you will come accross:

  • float~It stores a float value
  • int~It stores an Integer value
  • String~It stores a string value(a text inside ” ” or ‘ ‘)
  • char~It stores a single charachter
  • date~It stores a date value
  • boolean~It stores a logical value (true or false/ 1 or 0)
  • and others…

In PHP all variables start with a “$” and it can can be an alphanumeric(0 to 9 and A to Z) and “_” and it is case sensetive.

You dont need to define variables in PHP just asign the value and it is defined automatically you can asign a variable to another one so you can have

$a=2;

$b=$a;

$b=5;

in this case $b is 2 and when you change $b to 5, you will have $a=2 and $b=5

Another thing you can do with variables is to refrence the variable using “&” sign so you can have

$a=2;

$b=&$a;

$b=5;

then what you have is $a=5 and $b=5 because you referenced them