Variables in PHP:
$
followed by the variable name. Example: $variableName
.$myVar
and $myvar
are treated as different variables).Assigning Values to Variables:
=
).Data Types in PHP: PHP supports various data types:
Scalars:
$age = 25;
$price = 10.99;
' '
or double quotes " "
. Example: $name = "John";
true
or false
. Example: $isLogged = true;
Compound Data Types:
php$colors = array("Red", "Green", "Blue");
// or in PHP 7+ using [] syntax:
$colors = ["Red", "Green", "Blue"];
Special Types:
$var = null;
Variable Naming Rules:
_
)._
.Dynamic Typing in PHP:
Example illustrating variable assignment and data types:
php$age = 30; // Integer
$price = 12.99; // Float
$name = "Alice"; // String
$isStudent = true; // Boolean
$dynamicVar = 50; // Assigned as integer
$dynamicVar = "Hello"; // Reassigned as string (dynamic typing)
Understanding variables and data types is fundamental in PHP programming, as they form the basis for storing and manipulating data within PHP scripts. These concepts are foundational and play a crucial role in web application development using PHP.
Thanks for learning