Oboe
No history yet

How to learn PHP?

Welcome! PHP is one of the most powerful and widely used languages on the web, powering over 75% of all websites. Learning it is like unlocking a superpower because you can build everything from simple blogs to massive web applications like Wikipedia and WordPress.

To make sure we build a learning path that matches exactly what you want to achieve, I'm doing a quick bit of research on the best way to get you up to speed with modern PHP practices.

Q: What depth of coverage are you looking for in this course? A: Deep dive (from absolute basics to building full, database-driven web apps)

A deep dive it is! Getting your hands dirty with real, database-driven web applications is by far the best way to master PHP because you get to see exactly how data flows from a user's browser, through your code, and into a database.

Based on your goal, I've mapped out a complete roadmap that starts with basic syntax and takes you all the way to building dynamic, interactive websites.

Your path
Basic Control Structures (conditionals, loops)
Working with Data (arrays, functions)
Dynamic Web Basics (handling form data, GET/POST)
Database Integration (saving and retrieving data)

Before we write our first line of code, let's understand how PHP actually works under the hood.

Normally, when you visit a basic website (like a simple HTML page), your browser just requests a file and the server sends it right back. But is different. It is a server-side scripting language.

This means that when a user requests a PHP page, the server doesn't just hand over the raw code. Instead, the server's PHP engine runs the code, translates all your logic into plain HTML, and then sends that clean HTML back to the visitor's browser. The visitor never sees your actual PHP code—they only see the result.

Let's kick things off with our very first milestone by looking at how a basic PHP block is structured.

<?php
  // This is how we write a message to the browser
  echo "Hello, Web!";
?>

Notice those strange symbols at the beginning and the end? The <?php acts like an opening gate, telling the server, "Hey, start reading this as programming logic!" The ?> is the closing gate that shuts the programming engine off. Inside, we use echo to output text, and we always end our statements with a semicolon ;.

To make sure this makes sense before we move to variables, let's try a quick puzzle.

Once you feel comfortable with this core concept, we will look at how PHP temporarily stores information using variables.

Answer: It tells the web server to start interpreting the following code as PHP.

Correct

PHP
LV 1
Skills

Spot on! That is exactly what it does. The web server sees <?php and instantly knows it has to wake up the PHP interpreter to run the code, rather than just passing it along as static text.

Now that you understand how PHP gets triggered on the server, let's look at how it keeps track of information while it runs. This is where come in.

In PHP, every single variable has a superpower: it must always start with a dollar sign $.

Let's see what this looks like in practice:

<?php
  $username = "Alice";
  $visitor_count = 42;

  echo "Welcome back, ";
  echo $username;
?>

Notice how we didn't have to tell PHP what type of data we were putting into the boxes. PHP is smart enough to realize that $username holds a piece of text (which we call a string), and $visitor_count holds a whole number (an integer).

Let's test this out with a quick checkpoint to see if you can spot how to correctly write a variable.

Once we have variables down, we can start combining them to build dynamic, personalized messages on the screen.

Answer: $userAge = 25;

Correct

PHP
LV 1
Skills

You nailed it! You recognized that a variable in PHP must always start with that $ sign, require no type declarations, and end with a semicolon. You're already picking up the syntax incredibly fast.

Now that we have variables working, we want to start gluing things together. In programming, joining strings of text and variables together to make a single sentence is called .

To link pieces of text together in PHP, we use a single dot . as our operator. Think of the dot like a dab of glue.

<?php
  $name = "Alice";
  // Gluing static text to our variable
  echo "Hello " . $name . "! Enjoy your stay.";
?>

By placing a . between `

Hello "andname,andanother.betweenname`, and another `.` between `nameand"! Enjoy your stay."`, PHP seamlessly merges them into a single line of text before sending it to the browser.

Let's check this out with a quick puzzle to see if you can spot how to glue two variables together.

Once you feel confident with gluing text, we will explore some neat shortcuts PHP offers for handling variables inside text.

Answer: echo $greeting . ", " . $name . "!";

Correct

PHP
LV 1
Skills

Excellent work! You perfectly tracked how to chain those four distinct pieces together using the dot . operator. You've officially mastered string concatenation in PHP.

While using the dot operator is great, writing out all those dots and quotes can get a bit tedious when you have a lot of variables. Fortunately, PHP has an amazing shortcut called variable .

When you wrap a string in double quotes "", PHP does a quick scan of the text. If it finds a variable starting with a dollar sign $ inside those quotes, it automatically replaces it with its actual value.

Let's compare the dot method with this double-quote shortcut side-by-side:

<?php
  $sport = "soccer";

  // Method 1: Concatenation (Gluing)
  echo "I love playing " . $sport . " on weekends.";

  // Method 2: Interpolation (The Shortcut)
  echo "I love playing $sport on weekends.";
?>

Both methods output the exact same sentence! However, there is a catch: this magical scanning process only happens when you use double quotes "". If you use single quotes '', PHP treats everything inside literally and will print the actual character $sport instead of the value "soccer".

Let's test this distinction with a quick check to see how PHP handles these different quotes.

Once you feel comfortable with how single and double quotes handle variables, we will be ready to wrap up our first milestone.

Answer: I love $sport

Correct

PHP
LV 2
Skills

Spot on! Because you used single quotes, PHP took your instructions literally and printed out the actual characters, dollar sign and all, instead of looking inside the box. You have officially mastered variables, concatenation, and quotation nuances!

With those fundamentals under your belt, we have successfully wrapped up our introduction to PHP. We are now ready to make our code make decisions on its own using control structures.

Your path
Working with Data (arrays, functions)
Dynamic Web Basics (handling form data, GET/POST)
Database Integration (saving and retrieving data)

Making Decisions with Conditionals

Right now, our code runs straight from top to bottom, executing every single line. But real web applications need to react dynamically to different situations—like displaying a "Log In" button if a user is a guest, or showing an "Admin Dashboard" link only if they have special permissions.

To do this, we use conditional statements, starting with the classic if and else structure. Think of an if statement like a fork in the road with a guard standing by. The guard checks a condition: if it is true, you take one path; if it's false, you take the other.

<?php
  $is_logged_in = true;

  if ($is_logged_in) {
      echo "Welcome back to your dashboard!";
  } else {
      echo "Please log in to continue.";
  }
?>

Notice how we use parentheses () to hold our question, and curly braces {} to wrap the actions. If $is_logged_in holds the value true, only the first block of code runs. If it's false, PHP skips the first block entirely and runs the code inside the else block instead.

Let's test this out with a quick check to see how PHP handles a number comparison in a decision.

Once you feel comfortable with how PHP branches its logic based on these conditions, we'll look at how we can check multiple conditions in a row.

Answer: Add more items.

Correct

PHP
LV 2
Skills

Brilliant! You recognized that since 3 is not greater than 5, the condition fell flat and PHP naturally executed the fallback else code. You have a perfect score on all checkpoints so far!

Now, life isn't always a simple, two-way street of yes or no. Often, you have multiple choices to sort through. For example, if you're building an e-commerce checkout, you might want to give a 20% discount to VIPs, a 10% discount to regular members, and no discount to guests. To handle this, we use the , statement.

An elseif sits right between your initial if and your final fallback else. You can stack as many of them as you need. PHP will check them one by one, from top to bottom, and execute the very first one that evaluates to true.

<?php
  $user_role = "member";

  if ($user_role === "vip") {
      echo "You get a 20% discount!";
  } elseif ($user_role === "member") {
      echo "You get a 10% discount!";
  } else {
      echo "Sign up to get discounts!";
  }
?>

Notice how we used three equals signs === to compare values? In PHP, this means we are checking if the value on the left is exactly equal to the value on the right, matching both the content and the data type.

Let's put this new multi-decision tool to the test with a quick checkpoint.

Once you feel confident in how PHP walks down these decision stairs, we'll dive into how to make code repeat itself using loops.

Answer: B

Correct

Computer Programming
LV 1
PHP
LV 2
Skills

Spot on again! You correctly noticed that even though $score is also greater than or equal to 50, PHP stops checking the chain the absolute second it finds its very first true match. You are officially maintaining a flawless streak across all checkpoints!

Now that our code can make decisions, we can teach it to perform repetitive tasks without breaking a sweat. In programming, when we want to run the same block of code over and over again, we use a loop.

Let's start with the simplest type of loop: the .

A while loop is like an automated gatekeeper. It checks a condition: while that condition remains true, it keeps running the code inside its curly braces. The second the condition becomes false, it shuts the loop down.

<?php
  $count = 1;

  while ($count <= 3) {
      echo "This is round " . $count . "<br>";
      $count = $count + 1; // Increment our counter
  }
?>

Let's walk through this step-by-step to see exactly how the server executes this loop:

  1. Setup: We declare $count and set it to 1.
  2. Round 1: PHP checks if 1 <= 3. It is! It prints "This is round 1" and then adds 1 to $count, making it 2.
  3. Round 2: PHP checks if 2 <= 3. Yes! It prints "This is round 2" and adds 1 to $count, making it 3.
  4. Round 3: PHP checks if 3 <= 3. Still true! It prints "This is round 3" and adds 1 to $count, making it 4.
  5. The Exit: PHP checks if 4 <= 3. This is false! PHP immediately exits the loop and moves on to any code below it.

Let's run a quick checkpoint on how a while loop changes variables during its cycles.

Once you feel comfortable with how the loop condition determines whether the code inside runs, we'll look at a more compact way to write loops when we know exactly how many times we want to repeat.