Introduction to PHP
PHP was created by Rasmus Lerdorf in 1994 — the name originally stood for "Personal Home Page" tools — as a quick way to generate dynamic HTML on a web server, one request at a time. That web-first history still shapes the language today: PHP is dynamically typed, interpreted (no compile step, same as Python or Ruby), and its standard library leans hard toward exactly the things a web backend needs most — string manipulation, array handling, and reading data that arrived over HTTP.
Normally a PHP script runs inside a web server, and two special arrays called superglobals — $_GET and $_POST — are filled in automatically with whatever data came in on the request: $_GET for a URL's query string, $_POST for a submitted form body. You never write the parsing code; PHP hands you the data already as an array. This site runs PHP scripts a different way — through its own compiler backend, via the command line, with any input arriving on stdin — so $_GET and $_POST won't show up with real data in this course. They're worth knowing conceptually anyway: once you understand PHP's associative arrays (a few lessons from now), you already understand the shape $_GET and $_POST take in real PHP code.
The other fact worth knowing up front: every PHP variable is $-prefixed. $name, not name. There's no declaration keyword of any kind — the first assignment to a $name brings it into existence, and a variable can hold a string on one line and an integer on the next with no error. PHP is dynamically typed from top to bottom, the same general family as Python, JavaScript, and Ruby.
A quick preview
Here's a real PHP program, executed for real on this page's own compiler — not a mockup. Every PHP script starts with an opening <?php tag; echo prints to standard output; and double-quoted strings interpolate $variables directly, no special prefix needed.
<?php $name = "World"; echo "Hello, $name!\n"; $nums = [1, 2, 3]; echo "Sum: " . array_sum($nums) . "\n";
Hello, World! Sum: 6
"Hello, $name!" wove $name's value straight into the string with no concatenation operator at all — that only works inside double quotes, which the next few lessons will come back to. [1, 2, 3] built an indexed array, and array_sum() is one of the hundreds of array functions the standard library ships because arrays are PHP's single most-used data structure. Next: your first program — the <?php tag, echo, comments, and what actually gets printed when a script runs.
Practice exercise
Create an array $nums containing 2, 4, and 6, then echo "Total: " followed by the result of array_sum($nums).