FREE COURSE | BEGINNER
PHP Fundamentals
Build dynamic server-side applications using PHP.
Learning objectives
Understand server execution, write PHP logic, process input safely and explore database connectivity.
Prerequisites: basic HTML and programming logic. Official PHP documentation.
01. Introduction to PHP
PHP is a server-side scripting language. The browser sends an HTTP request, the server executes PHP, and the browser receives the generated response, not the PHP source.
PHP example
Original example output
Reveal expected output
Hello, LOOPNODELAB!
Edited PHP must be run in your local PHP runtime. This output belongs to the original example only.
Try it yourself
Predict the output before revealing it.
02. Setup and PHP Syntax
Install a supported PHP 8.x runtime or use a PHP-enabled local environment. Save a file as index.php and run php -S localhost:8000 from its directory for local development only. PHP statements normally end with a semicolon.
PHP example
Original example output
Reveal expected output
Welcome to PHP!
Edited PHP must be run in your local PHP runtime. This output belongs to the original example only.
Try it yourself
Change the greeting in your local file.
03. Variables, Data Types and Operators
Variables start with $. PHP supports strings, integers, floats, booleans and arrays. Use . to concatenate strings and arithmetic operators to calculate values.
PHP example
Original example output
Reveal expected output
Learner: 360
Edited PHP must be run in your local PHP runtime. This output belongs to the original example only.
Try it yourself
Calculate the total for five items.
04. Conditions and Loops
Use if, elseif and else to make decisions. Use for or foreach to repeat operations. Strict equality (===) compares both type and value.
PHP example
Original example output
Reveal expected output
Passed 1 2 3
Edited PHP must be run in your local PHP runtime. This output belongs to the original example only.
Try it yourself
Predict the result for a score of 70.
05. Arrays and Functions
Indexed arrays store ordered values; associative arrays use named keys. Functions group reusable logic and can return a result.
PHP example
Original example output
Reveal expected output
350
Edited PHP must be run in your local PHP runtime. This output belongs to the original example only.
Try it yourself
Add another price and calculate the new total.
06. Forms, GET and POST
GET typically retrieves information and puts parameters in the URL. POST submits data in the request body; it does not encrypt it. Use HTTPS, validate input on the server, and escape output for HTML. This example uses sample data instead of a real request.
PHP example
Original example output
Reveal expected output
<Learner>
Edited PHP must be run in your local PHP runtime. This output belongs to the original example only.
Try it yourself
Explain why escaping is needed before displaying user input.
07. Database Connectivity and Security
PDO connects PHP to databases. Prepared statements separate SQL from input values. Keep credentials outside public files, use least-privilege accounts and never expose database errors to visitors.
PHP example
Original example output
Reveal expected output
Requires a configured database; not executed.
Edited PHP must be run in your local PHP runtime. This output belongs to the original example only.
Try it yourself
Identify the placeholder and the bound value.
08. Interactive Practice Lab
Practice the same arithmetic and conditional logic used in PHP. The browser activity below is a JavaScript simulation, not a PHP interpreter. Compare your prediction with its result.
PHP example
Original example output
Reveal expected output
Regular price
Edited PHP must be run in your local PHP runtime. This output belongs to the original example only.
Try it yourself
Try quantities 3 and 5. Explain why the result changes.
Order calculator — browser simulation
09. Mini Project: Order Calculator
Build a local PHP order calculator. Accept a quantity, validate it as an integer between 1 and 100, calculate a total and display the result. The sample uses a fixed input; extend it with a POST form locally.
PHP example
Original example output
Reveal expected output
Total: 600
Edited PHP must be run in your local PHP runtime. This output belongs to the original example only.
Try it yourself
Test valid, negative and nonnumeric quantities locally.