📄️ Basic Functions
Welcome to your first lesson on functions. We have been using some built-in functions in PHP, but now we are going to learn how to create our own functions.
📄️ Function Parameters
We saw how to create a very basic function in the last lesson. We also saw that a value can be returned from a function. In this lesson, we will learn how to have a function accept parameters. Parameters can be used to change the way a function works.
📄️ Variable Scope
In this lesson, we're going to talk about something called 'scope'. Scope refers to the visibility of variables. In other words, where can we access a variable from?
📄️ Constants
In PHP, we have something called constants. Constants are similar to variables, but they cannot be changed. They are useful for storing values that you know will never change, such as the name of your application, your database info or the version number. You will see constants a lot inside of config files.
📄️ Type Declarations
As I have said before, PHP is a dynamically typed language. We do not have to declare the type of a variable when we create it. PHP will automatically determine the type of a variable based on the value that we assign to it. This is true by default, BUT we can change this behavior by using type declarations, which were introduced in PHP5. This is completely optional, but it can be useful in some situations.
📄️ Job Listings Helper Functions
Now that you know how to create functions, let's create some helper functions for our job listings page.
📄️ Average Salary Challenge
In this challenge, I want you to create a function that will calculate the average salary of the salaries in the job listings.
📄️ Anonymous Functions and Closures
Up to this point, we have been using named functions in PHP, which is definitely the most common type. However, we also have the option to use anonymous functions, also called lambda functions. There are a few different types of anonymous functions such as closures and callbacks. I will give you some simple examples of these.
📄️ Callback Functions
Another way to use an anonymous function is to pass it as an argument to another function. This is calles a callback function. It gets passed in and is called back later on within the function it was passed into.
📄️ arrow-functions
Arrow Functions
📄️ Format Salary Lambda Refactor
In this lesson, I want you to do a couple things in the job listings page that we have been working with.
📄️ Function Challenges
Up to this point in the course, we have looked at variables, arrays, loops, conditionals, and functions. We will now put all of this knowledge together to solve some problems.