New video tutorials on creating custom functions in PHP

New FREE PHP video tutorial of the week

How and why to create a simple custom function - 3:09

So far we've looked at a number of built-in functions for PHP, but this week we're going to start writing our own! Functions are a great way to create reusable code snippets, and as we'll see in upcoming videos, they also give us some flexibility in how the code gets executed.

New PHP videos on creating custom functions

This week we start digging into creating our own custom functions. Functions give us the freedom to execute code snippets wherever we need to without copying and pasting existing code. Logically, functions help us organize functionality into reasonable pieces that will help us understand our code later, or will help other team members get a sense of what certain code is for. From this point forward, functions will form a large part of how we structure our code, so it's good to make sure you have a solid grasp of what's going on.

How to create a function that accepts parameters - 1:35

Now that you know how to create a function, we'll look at how to pass data to it in the form of a parameter. Parameters are just variables we can use within our functions, but being able to use them packs a lot of power when it comes to writing code.

How to create a function that has optional parameters and build a virtual dice roller - 4:05

In this video we walk through creating a classic dice roller application using a custom function. We also explore the idea of optional parameters to allow flexibility but simplify code when possible.

A deeper explanation of the purpose of custom functions - 1:46

In this brief video, we explain how custom functions can evolve and become more powerful than using loops or copying and pasting code to get the same logic to run.

How to work with references in a function (i.e. variables with an ampersand) - 4:14

You'll probably run across references in Drupal's code before you actually have a need to use them yourself, so it's good to get a sense for what they do and how they work. References are basically variables that get passed into a function as a pointer to existing variable data. And if that doesn't make any sense, check out the video and it will soon!