Skip to content
Justice Tech School

PHP Tutorial

The server side language behind much of the web.

Start learning PHP
Getting started4 lessons
  1. 1PHP IntroductionWhat PHP is and what it powers.
  2. 2Syntax and Outputecho, print and comments.
  3. 3PHP Install and RunInstall PHP from php.net or with XAMPP, Laragon or Docker.
  4. 4PHP CommentsPHP supports // and # for one line and /* */ for several lines.
Basics20 lessons
  1. 5VariablesNames that start with $.
  2. 6Data Typesstring, int, float, bool, array, null.
  3. 7StringsWorking with text.
  4. 8Numbers and Mathint, float and math functions.
  5. 9OperatorsComparison, logic and null handling.
  6. 10echo, print and printfecho prints several values, print returns 1, and printf and sprintf format with %s %d %f.
  7. 11PHP Constants and Magic Constantsdefine() and const create constants.
  8. 12PHP Type Juggling and CastingPHP converts types automatically.
  9. 13null, isset and emptynull means no value.
  10. 14More String Functionstrim, ltrim, rtrim, ucwords, wordwrap, nl2br, str_pad, str_repeat, strrev, similar_text, l.
  11. 15PHP Math and Random NumbersFunctions: abs, ceil, floor, round, sqrt, pow, fmod, max, min, pi, rand, mt_rand and rando.
  12. 16PHP Tags and StatementsPHP code lives between <?php and ?>.
  13. 17Variables in DepthVariables start with $ and are case sensitive.
  14. 18String Interpolation and HeredocDouble quoted strings read variables inside.
  15. 19Integers and FloatsPHP has int and float.
  16. 20Casting and ConversionCast with (int), (float), (string), (bool) and (array).
  17. 21== and ===== compares after type juggling, === compares value and type.
  18. 22Null Coalescing?? returns the left value if it exists and is not null, otherwise the right.
  19. 23Constants and Magic Constantsdefine() and const create constants.
  20. 24Operators SummaryArithmetic, assignment (+=, .=), comparison, logical (&&, ||, and, or), string (.) and inc.
Control flow10 lessons
  1. 25If, Else and MatchMaking decisions.
  2. 26Loopswhile, for and foreach.
  3. 27Switch and Match In Depthswitch falls through without break and compares loosely.
  4. 28break, continue and Alternative Syntaxbreak exits a loop and continue skips a round.
  5. 29Ternary, Spaceship and Null SafeThe ternary ?: shortens if else.
  6. 30if, elseif and elseRun code by condition.
  7. 31match Expressionmatch returns a value, compares strictly and throws if nothing matches unless you add defa.
  8. 32for and while Loopsfor has init, condition and step.
  9. 33foreachforeach walks arrays with values or keys and values.
  10. 34break and continuebreak stops a loop and continue skips to the next round.
Arrays and functions28 lessons
  1. 35ArraysIndexed and associative arrays.
  2. 36Array Functionsmap, filter, reduce and sorting.
  3. 37FunctionsReusable code.
  4. 38Variable ScopeLocal, global and static.
  5. 39Sorting Arrayssort and rsort reorder values, asort and arsort keep keys, ksort and krsort sort by key an.
  6. 40Multidimensional ArraysArrays can contain arrays.
  7. 41More Array Functionsarray_merge, array_combine, array_flip, array_unique, array_slice, array_splice, array_sea.
  8. 42Spread and DestructuringThe .
  9. 43Closures and CallablesAnonymous functions can capture variables with use.
  10. 44Recursion and GeneratorsA function can call itself.
  11. 45ArraysPHP arrays are ordered maps.
  12. 46Adding and Removing Itemsarray_push, array_pop, array_shift, array_unshift, unset and array_splice change arrays.
  13. 47Searching Arraysin_array tests presence, array_search finds the key, array_key_exists checks a key and iss.
  14. 48array_map, array_filter, array_reduceTransform, select and fold arrays with callbacks.
  15. 49array_slice, merge and combinearray_slice takes a part, array_merge joins arrays, array_combine pairs keys and values an.
  16. 50Unique, Count and Statisticsarray_unique removes duplicates, array_count_values counts, array_sum and max compute tota.
  17. 51Sortingsort and rsort sort values, asort and arsort keep keys, ksort sorts by key and usort uses .
  18. 52implode, explode and str_splitexplode splits text into an array and implode joins an array into text.
  19. 53FunctionsDefine with function.
  20. 54Named and Variadic ArgumentsNamed arguments choose parameters by name.
  21. 55Arrow Functions and Closuresfn creates short functions that capture outer variables by value.
  22. 56Variable Scope and staticVariables inside functions are local.
  23. 57Type DeclarationsAdd types to parameters and returns.
  24. 58More String Functionsstrlen, strtoupper, ucfirst, trim, str_replace, substr, strpos and str_contains cover most.
  25. 59Checking Stringsstr_contains, str_starts_with and str_ends_with give clear answers.
  26. 60Formatting Numbersnumber_format adds separators and decimals.
  27. 61Datesdate() formats a timestamp, mktime and strtotime create timestamps and DateTime is the mod.
  28. 62Math Functionsabs, sqrt, pow, max, min, pi, round and random_int help with numbers.
Object oriented PHP16 lessons
  1. 63Classes and ObjectsProperties, methods and constructors.
  2. 64Inheritance and InterfacesExtending and contracts.
  3. 65Static Members, Constants and TraitsClass level things and reuse.
  4. 66Constructors, Readonly and EnumsConstructor promotion declares properties in the constructor.
  5. 67Abstract Classes and InterfacesAn abstract class cannot be instantiated and can mix implemented and abstract methods.
  6. 68Magic Methods__construct, __destruct, __toString, __get, __set, __call, __invoke and __clone run in spe.
  7. 69Namespaces and AutoloadingNamespaces avoid name clashes and use imports them.
  8. 70Type Declarations and Union TypesDeclare parameter, return and property types.
  9. 71Classes and ObjectsA class holds properties and methods.
  10. 72public, protected, privatepublic is open, protected is for the class and children, private is for the class only.
  11. 73Inheritanceextends inherits members and parent:: calls the parent.
  12. 74InterfacesAn interface lists methods a class must write.
  13. 75Static Members and Class Constantsstatic belongs to the class and const holds fixed values.
  14. 76EnumsEnums (PHP 8.1) define a fixed set of cases, optionally backed by values.
  15. 77readonly Propertiesreadonly properties can be set once, then never changed.
  16. 78Exceptionsthrow an Exception and catch it with try catch.
Web features and data24 lessons
  1. 79Forms and Superglobals$_GET, $_POST and $_SERVER.
  2. 80Sessions and CookiesRemembering visitors.
  3. 81JSONjson_encode and json_decode.
  4. 82FilesReading and writing.
  5. 83Databases with PDOSafe queries with prepared statements.
  6. 84Errors and Exceptionstry, catch and throw.
  7. 85Dates and Regular Expressionsdate(), DateTime and preg functions.
  8. 86Form Handling and ValidationCheck request method, validate every input with filter_var and rules, show errors and esca.
  9. 87File UploadsForms with enctype multipart/form-data fill $_FILES.
  10. 88Passwords and SecurityHash passwords with password_hash and check them with password_verify.
  11. 89HTTP Requests with cURLcURL fetches URLs.
  12. 90Headers, Redirects and Status Codesheader() sends HTTP headers before any output.
  13. 91Regular Expressions In Depthpreg_match with named groups, preg_replace_callback, preg_split and preg_quote.
  14. 92DateTime In DepthDateTimeImmutable never changes in place.
  15. 93JSONjson_encode turns data into JSON and json_decode reads it.
  16. 94Superglobals$_GET, $_POST, $_SERVER, $_COOKIE, $_SESSION and $_FILES carry request data.
  17. 95Escaping Outputhtmlspecialchars stops XSS by turning < and > into entities.
  18. 96Validating Input with filter_varfilter_var validates emails, URLs and integers and sanitises values.
  19. 97Reading and Writing Filesfile_put_contents and file_get_contents are the quick way.
  20. 98Regular Expressionspreg_match tests a pattern, preg_replace replaces and preg_split splits.
  21. 99Password Hashingpassword_hash makes a salted hash and password_verify checks it.
  22. 100Practice: Word CounterCombine strings and arrays to count words.
  23. 101Practice: FizzBuzzLoop with conditions.
  24. 102Practice: Simple CartUse arrays of arrays and array_sum with array_column.
Advanced PHPPremium6 lessons
  1. 103Composer and PackagesComposer manages PHP dependencies.
  2. 104PDO Transactions and Fetch ModesWrap related writes in beginTransaction and commit, and roll back on error so the data sta.
  3. 105Preventing SQL InjectionNever put user input into SQL strings.
  4. 106Authentication FlowA login form posts credentials, the server checks password_verify, regenerates the session.
  5. 107Testing with PHPUnitPHPUnit is the standard test framework.
  6. 108Performance and OPcacheOPcache keeps compiled PHP in memory.
PHP in practicePremium6 lessons
  1. 109Building a REST APIReturn JSON with proper status codes, route by method and path, validate input and version.
  2. 110Laravel OverviewLaravel is the most popular PHP framework.
  3. 111WordPress and PHPWordPress is written in PHP.
  4. 112Templates and Separation of ConcernsKeep logic and HTML apart.
  5. 113Logging and Error ReportingShow errors in development only.
  6. 114PHP Best PracticesUse strict types, type declarations, PSR-12 style, Composer, prepared statements, password.
Next steps2 lessons
  1. 115What Next?Where to go after the basics.
  2. 116Practice ProjectsBuild a blog with a database, a login system, a REST API and a small shop with Laravel.