PHP Guide
PHPServer-Side Scripting
Learn PHP fundamentals, object-oriented programming, database integration, and building dynamic web applications.
Contents
PHP Basics
PHP is a server-side scripting language designed for web development. Learn syntax, variables, arrays, and control structures.
php
<?php
// Variables
$name = "John";
$age = 30;
$isActive = true;
// Arrays
$fruits = array("Apple", "Banana", "Orange");
$numbers = [1, 2, 3, 4, 5];
// Associative Arrays
$user = [
"name" => "John",
"email" => "john@example.com",
"age" => 30
];
// Control Structures
if ($age >= 18) {
echo "Adult";
} else {
echo "Minor";
}
// Switch
switch ($age) {
case 18:
echo "Just turned 18";
break;
case 21:
echo "Legal drinking age";
break;
default:
echo "Other age";
}
// Loops
for ($i = 0; $i < 10; $i++) {
echo $i;
}
foreach ($fruits as $fruit) {
echo $fruit;
}
foreach ($user as $key => $value) {
echo "$key: $value";
}
// String Concatenation
$greeting = "Hello, " . $name . "!";
$greeting = "Hello, {$name}!";
?>