PHP_Syntax_Explained
PHP_Syntax_Explained
Example:
<?php
echo "Hello, World!";
?>
2. Comments in PHP
PHP supports single-line and multi-line comments.
Examples:
// Single-line comment
# Another single-line comment
/* Multi-line comment */
3. Variables in PHP
Variables in PHP store data and start with a `$` symbol.
Example:
$name = "John";
$age = 25;
$price = 10.5;
Example:
$integer = 100;
$float = 10.5;
$string = "Hello";
Example:
if ($age >= 18) {
echo "You are an adult.";
} else {
echo "You are a minor.";
}
6. Loops in PHP
Loops allow executing a block of code multiple times.
7. Functions in PHP
Functions help in organizing reusable blocks of code.
Example:
function greet($name) {
return "Hello, " . $name . "!";
}
echo greet("Alice");
8. Arrays in PHP
Arrays store multiple values in a single variable.