PHP for the Web·PHP from first script to a working app

Setup and syntax

Run PHP from the terminal and learn variables, types, output and strict mode.

Beginner 12 min read Lesson 1 of 300 Challenge included
What you will be able to do
  • Start PHP code with the opening tag and end it only when mixing HTML.
  • Use declare(strict_types=1) at the top of every file.
  • Prefer single quotes when you do not need interpolation.
  • Inspect values with var_dump while developing.

In plain English

PHP runs on the server and sends finished HTML to the browser. A file starts in HTML mode and switches into PHP with an opening tag. Strict types turn accidental string-to-number coercion into visible errors, which is exactly what you want while learning.

hello.phpPHP
<?php
declare(strict_types=1);

$name = 'Ada';
$score = 91.5;
$active = true;

echo "Hello, {$name}! Score: {$score}\n";
var_dump($active);
Your turn

Print a formatted line

Easy

Create variables for a course title and a lesson count, then print "CSS has 16 lessons" using interpolation.

PHP · starter
<?php
$title = 'CSS';
$lessons = 16;
// print the line
Check your understanding before moving on.
Knowledge checkQuestion 1

What does declare(strict_types=1) change?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Control flow and loops
Lesson 1 of 300 · 0% of course