PHP is a server-side scripting language primarily used for web development. It can generate dynamic page content, interact with databases, handle forms, and more.
Here's a basic "Hello, World!" program in PHP:
<?php
echo "Hello, World!";
?>
PHP supports variables and operations similarly to other languages:
<?php
$a = 10;
$b = 5;
$sum = $a + $b;
$product = $a * $b;
echo "Sum: $sum";
echo "Product: $product";
?>
Using conditional statements in PHP:
<?php
$number = 10;
if ($number > 0) {
echo "The number is positive.";
} else {
echo "The number is not positive.";
}
?>
Example of a loop in PHP:
<?php
for ($i = 1; $i <= 5; $i++) {
echo "Number: $i <br>";
}
?>