PHP Overview

Variables

PHP variables start with a $ symbol and are dynamically typed.

$name = "John";
$age = 25;
$price = 19.99;
$is_available = true;

Data Types

Arrays

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

Conditional Statements

If-Else

$age = 20;
if ($age >= 18) {
    echo "Adult";
} else {
    echo "Minor";
}

Switch

$color = "red";
switch ($color) {
    case "red":
        echo "Color is red";
        break;
    case "blue":
        echo "Color is blue";
        break;
    default:
        echo "Unknown color";
}