Hello, PHP
PHP runs a huge share of the web, including WordPress and Wikipedia. It is usually run by a web server to build pages, but it is a full programming language, and here it runs right in your browser.
Every PHP file starts with <?php. Printing uses echo:
<?php
echo "Mhoro!\n";
echo 2 + 3, "\n";
\n inside double quotes is a new line. Each statement ends with a semicolon.
Variables
Variable names start with a dollar sign:
$city = "Gweru";
$population = 158000;
$population = $population + 2000;
Joining text
The dot . joins strings:
echo $city . " has " . $population . " people\n";
Inside double quotes, variables are filled in automatically, which is often neater:
echo "$city has $population people\n";
Single quotes ('...') take text literally: no variables and no \n.
The first run downloads PHP (about 12 MB); after that it is quick.
Your task
- Print
Hello, PHP!. - Create
$shopwith the textMama's Kitchenand$mealswith the number12. - Print
Mama's Kitchen sold 12 mealsusing your variables.