- Basic PHP setup Before writing any PHP, you’ll usually have a file like index.php on a server with PHP installed. Everything between is treated as PHP code.
<?php
// Your PHP code will go here
?>
- Variables Variables store data like text, numbers, or booleans. In PHP they always start with $ and you don’t declare the type.
<?php
$name = "Alice"; // string
$age = 25; // integer
$price = 19.99; // float
$isAdmin = true; // boolean
echo $name;
echo $age;
?>
- Outputting text You often use echo to send text to the browser. You can combine variables and text using the . concatenation operator.
<?php
echo "Hello World!";
echo '
';
echo "My name is " . $name;
?>