What are Variables ?
Variable are some area, block or memory space to store data, a value such a text or number or array or anything else.
How to use Variables in php?
In our script, we can use variables over and over and this will not make any problem, and using variables is in two ways:
-Writing to a variable: we can write to a variable some value, such texts (strings) or numbers, and we can also write to a variable that don't exist, php will declare it automatically with the right type.
This is how we write to variable:
<?php
$mystring = 'Hello world';
$mynumber = 2008 ;
?>
$mystring = 'Hello world';
$mynumber = 2008 ;
?>
<?php
$mystring = 'Hello world';
$mymessage = $mystring ; // This will copy the value of mystring to mymessage
$mynumber = 2008 ;
?>
$mystring = 'Hello world';
$mymessage = $mystring ; // This will copy the value of mystring to mymessage
$mynumber = 2008 ;
?>
In php there are no types for variables, that why we don't have to declare them. For example if we write a number into a variable that contains string, this variable will be converted automatically to a number variable.
<?php
$myvar = 'Hello world'; // This variable contain a string
$myvar = 2008 ; // The same variable converted to number
?>
$myvar = 'Hello world'; // This variable contain a string
$myvar = 2008 ; // The same variable converted to number
?>