PHP variables start with a $
symbol and are dynamically typed.
$name = "John";
$age = 25;
$price = 19.99;
$is_available = true;
[1, 2, 3]
PHP supports indexed and associative arrays.
// Indexed Array
$fruits = ["Apple", "Banana", "Cherry"];
// Associative Array
$person = ["name" => "John", "age" => 25];
// Accessing elements
echo $fruits[0]; // Apple
echo $person["name"]; // John
$age = 20;
if ($age >= 18) {
echo "Adult";
} else {
echo "Minor";
}
$color = "red";
switch ($color) {
case "red":
echo "Color is red";
break;
case "blue":
echo "Color is blue";
break;
default:
echo "Unknown color";
}