PHP
The server language behind a huge part of the web
Syntax and variables, arrays and functions, forms and sessions, OOP, and connecting to MySQL safely with PDO — with PHP 8 running right in your browser.
- 47 lessons
- 7 chapters
- Arabic & English
Your progress
What's inside
Lessons go from the basics to advanced topics. Read them in order, or jump to what you need.
Chapter 1
Getting Started
- 1PHP IntroductionMeet PHP: the server-side language behind a huge part of the web. Learn how it works and why it's still a strong choice in its modern PHP 8 form.
- 2Install and Run PHPSet up PHP on your computer with XAMPP or Laragon, then run your files from the terminal or with the built-in development server php -S.
- 3PHP SyntaxLearn PHP's writing rules: the <?php tag, semicolons at the end of statements, blocks in curly braces, and which names are case-sensitive.
- 4PHP CommentsWrite notes in your code that PHP ignores, using single-line comments // and #, multi-line comments /* */, and documentation comments (DocBlocks).
- 5PHP echo and printOutput text and values with echo and print, learn how they differ, print several values at once, insert variables into strings, and inspect data with print_r and var_dump.
Chapter 2
PHP Basics
- 6PHP VariablesStore data in variables that start with $, learn the naming rules, how to change values, and why you don't declare types in advance.
- 7PHP Data TypesGet to know PHP's data types: strings, integers, floats, booleans, arrays, objects and null. Inspect them with var_dump() and convert between them.
- 8PHP StringsCreate strings with single and double quotes, join them with the dot operator, insert variables, use escape sequences, and write long text with heredoc and nowdoc.
- 9PHP String FunctionsUse built-in functions to process text: measure length, change case, search and replace, extract parts, split and join, and format with sprintf().
- 10PHP Numbers and MathWork with integers and floats: division, modulus and powers, float precision, rounding and math functions, and formatting numbers for display.
- 11PHP ConstantsDefine values that never change with const and define(), and meet built-in and magic constants such as __LINE__ and __DIR__.
- 12PHP OperatorsLearn PHP's operators: assignment, increment, comparison (including ==, === and <=>), logical operators, the null coalescing operator ??, and the ternary operator.
Chapter 3
Control Flow
- 13PHP if...elseMake decisions in your program with if, else and elseif, combine conditions with logical operators, and use the alternative syntax inside HTML templates.
- 14PHP switchChoose one of many paths based on a single value with switch, and understand the role of break and fall-through.
- 15PHP match ExpressionUse PHP 8's match expression: a shorter, safer alternative to switch that returns a value, compares strictly, and needs no break.
- 16PHP while LoopsRepeat code while a condition is true with while, run it at least once with do...while, and avoid infinite loops.
- 17PHP for LoopUse the for loop when you know how many times to repeat: initialization, condition and step in one line, with countdowns and nested loops.
- 18PHP foreach LoopWalk through arrays easily with foreach: values only, keys with values, modifying items by reference, and destructuring nested arrays.
- 19PHP break and continueControl your loops: stop them completely with break, or skip the current iteration with continue, even in nested loops.
Chapter 4
Functions
- 20PHP FunctionsDefine your own functions with function, pass them arguments, send results back with return, and write organized, reusable code.
- 21Function Parameters and TypesMake your functions clearer and safer: declare parameter and return types, use default values and named arguments, and accept any number of arguments.
- 22PHP Variable ScopeUnderstand where each variable can be used: local scope inside functions, global scope and the global keyword, and static variables that keep their value between calls.
- 23Anonymous and Arrow FunctionsCreate functions without names and store them in variables, capture outside variables with use, write short arrow functions with fn, and pass functions to other functions.
Chapter 5
Arrays
- 24PHP Indexed ArraysStore a list of values in one variable, read items by index, add, change and remove items, count them, loop over them, and unpack them into variables.
- 25PHP Associative ArraysUse meaningful string keys instead of numbers, add, change and remove values, check whether keys exist, and loop over key/value pairs with foreach.
- 26PHP Multidimensional ArraysStore complex data as arrays inside arrays, such as a list of students each with their own details, then read, update, loop over them, and extract whole columns.
- 27PHP Array FunctionsSort, search and transform arrays: the sort family, array_map, array_filter, array_reduce, in_array, array_search, array_merge and more.
Chapter 6
Object-Oriented Programming
- 28PHP Classes and ObjectsEnter object-oriented programming: define a class with properties and methods, create objects with new, and use $this to access an object's data.
- 29PHP ConstructorsInitialize objects the moment they're created with __construct(), shorten your code with PHP 8 constructor property promotion, and meet the destructor.
- 30Access Modifiers and readonlyProtect your objects' data with public, protected and private, write accessor methods with validation, and make properties read-only with readonly.
- 31PHP InheritanceBuild new classes on top of existing ones with extends, override methods, call the parent class with parent::, and prevent inheritance with final.
- 32Abstract Classes and InterfacesDesign clear contracts between the parts of your program: abstract classes that share common code, and interfaces that define what a class must implement.
- 33Static Members and Class ConstantsLearn about static properties and methods that belong to the class itself rather than to an object, class constants, and the difference between self:: and static::.
- 34PHP TraitsShare methods between unrelated classes without inheritance using traits, combine several traits, and resolve name conflicts between them.
- 35PHP EnumsDefine a fixed set of possible values with enum (PHP 8.1): pure and backed enums, from(), tryFrom() and cases(), and adding methods to enums.
- 36PHP ExceptionsHandle errors professionally: throw exceptions with throw, catch them with try, catch and finally, and create your own exception classes.
- 37Namespaces and AutoloadingOrganize your classes in namespaces to avoid name collisions, import them with use, and let Composer load their files automatically following PSR-4.
Chapter 7
Web & Data
- 38PHP SuperglobalsMeet the built-in arrays that are available everywhere: $_GET and $_POST for request data, $_SERVER for server and request information, and more.
- 39PHP Forms and ValidationHandle form data safely: validate required fields, emails and lengths, show error messages, keep the user's input, and follow the PRG pattern.
- 40PHP Sessions and CookiesKeep user data between requests: sessions ($_SESSION) store data on the server, such as login state, and cookies store small preferences in the browser.
- 41PHP include and requireSplit your site into reusable files and load them with include, require and their _once versions; learn how they differ and when to use each.
- 42PHP JSONConvert PHP arrays and objects to JSON with json_encode(), turn JSON back into PHP data with json_decode(), and handle errors and Arabic text.
- 43PHP Date and TimeFormat dates with date() and work with them professionally using DateTime and DateTimeImmutable: adding, subtracting, differences, and time zones.
- 44PHP MySQL with PDOConnect to MySQL with PDO, run Create/Read/Update/Delete (CRUD) operations safely with prepared statements, and use transactions.
- 45PHP Security BasicsProtect your application from the most common attacks: XSS with htmlspecialchars(), SQL injection with prepared statements, safe password storage with password_hash(), and CSRF with random tokens.
- 46PHP ComposerUse Composer, PHP's standard package manager, to install libraries, manage your project's dependencies, and autoload classes, and understand composer.json and composer.lock.
- 47PHP Next StepsReview what you've learned with a mini project that combines everything, discover best practices and professional tools, and plan your path to Laravel.