PHP from the ground up
The language behind the web page
- Beginner
- 13 chapters
- 201 min read
Learn PHP by running it: variables and types, strings, numbers and money, decisions and the equality trap, loops, arrays and their functions, your own functions, classes, inheritance and interfaces, errors and validation, and an expense report that uses the whole course at once.
What You'll Learn
- Write and run a PHP script, and know what the opening tag does
- Hold values in variables, and inspect types instead of guessing
- Clean up, join and format text with the everyday string functions
- Do arithmetic that adds up, including division, remainders and money
- Branch with if, ternary and match — and compare with === as the default
- Repeat work with for and while, and leave a loop early on purpose
- Use arrays as lists and as keyed records, and loop with foreach
- Replace whole classes of loops with map, filter, reduce and sort
- Write typed functions with defaults and return types, under strict mode
- Build classes with constructors, methods and visibility
- Extend a class and implement an interface, and use polymorphism
- Validate at the edge, throw with a reason, and catch what you can handle
- Assemble a typed expense report with classes, functions and array functions
Prerequisites
- No programming experience needed — this course starts at the first line
- Comfort with a web page (HTML) helps you see where PHP output goes
Course Content
- 01Your first PHP scriptNot started
The opening tag that makes a file PHP, echo as the way to say something, and the dot that joins pieces of text together.
- 02Variables and typesNot started
The dollar sign, the eight kinds of value PHP has, looking at a value's type instead of guessing, and converting between them on purpose.
- 03Strings that do workNot started
Single and double quotes and what each does with $, interpolation, and the handful of string functions that turn raw text into something presentable.
- 04Numbers and moneyNot started
Integer and float arithmetic, division that stays whole, powers and rounding, and the function that turns a raw number into money people can read.
- 05Decisions: if, and the equality trapNot started
Branching with if and elseif, choosing between two values with a ternary, the match expression, and the one comparison rule that saves the most debugging time.
- 06LoopsNot started
Repeating work a known number of times with for, an unknown number with while, and the two statements that skip an iteration or leave the loop early.
- 07Arrays: lists and lookup tablesNot started
One type, two habits — a numbered list and a keyed table — plus count, foreach, and the difference between an array and a fact.
- 08Array functions instead of loopsNot started
Map, filter and sort: the operations that loops were doing, said by name — and the arrow functions that describe each one in a line.
- 09Functions of your ownNot started
Naming a piece of work once, parameters and their defaults, return types, and the strict mode that turns quiet conversions into loud mistakes.
- 10Classes: your own typesNot started
Bundling data with the functions that work on it: properties, a constructor, methods, $this, and the visibility keywords that keep the inside inside.
- 11Inheritance and interfacesNot started
Extending a class to change part of it, an interface as a promise several classes can keep, and the polymorphism that lets one function accept all of them.
- 12Errors, and checking what arrivesNot started
Throw when a value cannot be used, catch where something can be done about it, and validate at the edge so the inside of the program only ever sees good data.
- 13Putting it together: an expense reportNot started
A capstone that uses the whole course once: a class for the records, functions for the work, array functions for the questions, formatting for the report.
