Beginner

The PHP Practitioner

We all start somewhere. When it comes to web development with PHP, well, your first stop is this series. Designed specifically and exclusively for beginners, here, you'll learn the fundamentals of PHP - all the way down to defining variables and arrays.

If you feel somewhat unprepared for the content at Laracasts, this "PHP for beginners" series should be your next stop. New lessons are published every Thursday, so don't fall behind!

Start Series

Share this series on:

  • 01

    Episode 1 Run Time 3:51

    Step 1: Get PHP Installed Free

    So you've decided to become a web developer? Excellent, excellent choice. At this point, you have a basic understanding of HTML and CSS, and are now ready to take the next step. Right? Great! Let's learn PHP from the ground up.

    Step 1 Homework: Get PHP 7, the latest version at the time of this recording, installed on your machine using one of the methods outlined above. You might use Homebrew on the Mac, or possibly MAMP, WAMP, or XAMPP. Any of these options will do just fine. To confirm that you've completed the homework, open the command line, and run php -v. Does it say PHP 7? Congrats!

  • 02

    Episode 2 Run Time 9:21

    Step 2: Install a Proper Code Editor Free

    Before we get started, let's ensure that you have a proper code editor installed on your machine. As you'll find, code editors are much like fashion: everyone has their own preference. It doesn't matter which you choose, so pick one!

    Step 2 Homework: Install a proper code editor on your machine right now. It could be Sublime Text, Atom, PHPStorm, or a different one entirely.

  • 03

    Episode 3 Run Time 7:37

    Step 3: Variables Free

    Now that you're ready to begin coding, let's start at the top. What exactly is a variable, and why would you ever use or need one?

    Step 3 Homework: Create a variable, and figure out how to echo it onto the screen or page.

  • 04

    Episode 4 Run Time 12:38

    Step 4: PHP and HTML Free

    PHP is a language built for the web. As such, it mixes with regular HTML beautifully. Let's learn how that all works in this episode. You'll review embedding PHP in HTML, calling your first function, and fetching URL parameters.

    Step 4 Homework: Echo a sentence onto the page, while fetching a URL parameters from the address bar.

  • 05

    Episode 5 Run Time 3:46

    Step 5: Separate PHP Logic From Presentation Free

    We'll touch on a slightly higher level topic in this episode, but only lightly. If you stick with it long enough, you'll begin to hear the phrase "separation of concerns." At our current skill level, this means we should give consideration to the fact that, at the moment, our PHP logic and HTML presentation are a bit too intertwined. Perhaps we can separate these concerns.

    Step 5 Homework: Play around with creating a new file, preparing a few variables, and then loading a separate "view" file to present the HTML.

  • 06

    Episode 6 Run Time 7:44

    Step 6: Understanding Arrays Free

    Let's learn about a new construct: arrays. Think of them as primitive collections of related data. Maybe you have an array of names, or animals, or practically anything. Even better, we can filter through this data and act upon it with ease.

    Step 6 Homework: Create an array of any five animals, and then loop over them with foreach, and display each one within a list item.

  • 07

    Episode 7 Run Time 12:04

    Step 7: Associative Arrays Free

    We've learned about basic arrays, but you may also creative associative arrays when necessary. The only difference is that each value within the array is associated with a key. Let me show you.

    Homework: Create an associative array for a task. This array should include such details as the title of the task, its due date, who it's assigned to, and whether it has been completed.

  • 08

    Episode 8 Run Time 10:44

    Step 8: Booleans Free

    "Boolean" is a scary, but simple term to understand. It's a data type that represents one of two values: true or false. As you'll find, you'll reference booleans constantly within your projects. So it's important that you understand this one.
  • 09

    Episode 9 Run Time 6:58

    Step 9: Conditionals Free

    A conditional is how we branch our logic into different paths. "If some value is true, then we want to proceed in this way. Otherwise, let's handle it in that way." As you can see, booleans and conditionals go hand-in-hand.

    Homework: Continue tinkering with conditionals. Add a new boolean to your task array, and use its value to branch off into two different paths within your HTML.

  • 10

    Episode 10 Run Time 7:49

    Step 10: Functions Free

    Think of a function as a container for reusable pieces of logic. In this lesson, you'll create your very first function.

    Homework: Write a function that determines if a provided age (sent through as an argument) is old enough to enter a 21-and-up night club. Have this function return a boolean, which can be used in any conditional.

  • 11

    Episode 11 Run Time 16:18

    MySQL 101 Free

    You've only just begun learning the fundamentals of PHP, and already I'm throwing something else at you. Sorry (bows head in shame), that's just how it is; there are lots of moving pieces to your typical web application. We must take some to review databases. This is how we "remember" information. Or, in other words, if a user creates a handful of todo items, how will we remember those todos for when they return to our site next week? Well, the answer is through a database.

    As for MySQL GUIs, you might consider any of the following:

  • 12

    Episode 12 Run Time 16:10

    Classes 101 Free

    I know you're excited about MySQL, and want to fetch records using PHP. However, we need to make one quick pit stop. We must learn the basics of writing classes, and creating objects. So let's tackle that in this episode, and then I promise we'll move on to writing SQL queries with PHP.
  • 13

    Episode 13 Run Time 15:16

    Intro to PDO Free

    Now that you understand what a class is, we can get back to fetching your first results from the database. To do so, we'll leverage PHP's PDO library, and create a prepared statement.
  • 14

    Episode 14 Run Time 17:39

    PDO Refactoring and Collaborators Free

    In this episode, you'll perform your first refactor. "Refactor" is a term we use to describe the process of changing the structure of your code, without affecting the underlying behavior. I'll be pushing your limits a bit in this episode, so you may need to watch this one twice. As always, ask any questions you mind have in the comments below.
  • 15

    Episode 15 Run Time 6:27

    Hide Your Secret Passwords Free

    At the moment, we're hardcoding our database username and password directly within the Connection class. But, we don't really want to do this. It's too dangerous. Instead, let's extract any secret passwords or keys for our app into its own file, and then lock that down.
  • 16

    Episode 16 Run Time 24:19

    Make a Router Free

    Let's discuss routing in this episode. While, yes, you can create PHP files that correspond to the URI, this breaks down pretty quickly. So instead, we'll make a very basic router. This allows us to associate any URI endpoint with a controller.

    View the source for this episode on GitHub.

  • 17

    Episode 17 Run Time 7:02

    Dry Up Your Views Free

    Let's take some time to work on our views. At the moment, we've been rewriting the entire wrapping HTML for every single page. Naturally, this breaks down very quickly in real life. Each time you update, say, your navigation area, you'd need to open several different view files to make the change. No thanks. Instead, let's review the first step to drying up your templates.
  • 18

    Episode 18 Run Time 13:31

    Array Filtering Free

    PHP's various array functions are tools that absolutely need to rest in your belt. While the good ole'foreach can usually get the job done, more often than not, there's a better way. In this episode, I'll introduce you to array_filter, array_map, and array_column.
  • 19

    Episode 19 Run Time 13:17

    Forms, Request Types, and Routing Free

    Let's transition over to working with forms. If we want a form's submission to POST to a particular endpoint, well, our router isn't yet set up to handle that. How exactly might we associate a URI with the request type (GET, POST) that it should respond to? In this episode, we'll do a bit of refactoring for this very thing!
  • 20

    Episode 20 Run Time 12:24

    Dynamic Inserts With PDO Free

    So far, we've only written the logic to fetch records from the database. But now it seems that we need to, not only insert new records, but do so dynamically. It sounds like we'll need to update our QueryBuilder class to allow for this.

    View the source code for this episode on GitHub.

  • 21

    Episode 21 Run Time 4:38

    Composer Autoloading Free

    No more PHP requires! They're annoying to write, aren't they? Instead, let's take some time to switch over to Composer, which is an industry standard for not just dependency management, but also autoloading.
  • 22

    Episode 22 Run Time 7:04

    Your First DI Container Free

    "Dependency injection Container" sounds like a super scary thing. But it's easy to understand! Think of them as boxes. Apply a label, and throw your stuff into the box. When you need them back, simply look for the corresponding label! In this episode, we'll transition from our simplistic $app array, to a dedicated DI container.
  • 23

    Episode 23 Run Time 17:34

    Refactoring to Controller Classes Free

    So far in this series, our "controllers" have simply been plain PHP files. In this episode, however, we'll refactor the router to allow for loading and calling actions on a controller class. I think you'll find that this drastically simplifies our workflow.
  • 24

    Episode 24 Run Time 14:52

    Switch to Namespaces Free

    At the moment, all of our classes share the same global namespace. But, think about it: you wouldn't throw your entire music collection into a single folder, and the same is true for your PHP classes. In this lesson, we'll switch over to dedicated namespaces, while discussing the benefits to doing so.
  • 25

    Episode 25 Run Time 17:26

    Meet Your Batteries Included Framework: Laravel Free

    It's time for you to meet my framework of choice: Laravel (duh). In this lesson, we'll review the basic folder structure, discuss how it is similar to the custom-built framework from this series, and then review why it's preferred, in this author's opinion, to choose a battle-tested solution like Laravel over manually wiring things together.

    So that brings this series to a close! Review the completed source code on GitHub. Your next stop should be Laravel From Scratch! Get to it.