From the course: PHP for WordPress
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
What are functions?
- [Instructor] Functions play an incredibly important role in PHP and WordPress, and you've seen them, but we haven't defined them yet. So let's go ahead and do that now. Functions are reusable snippets of code that could be used multiple times. You can imagine functions like variables for lines or blocks of code, and there are two types of functions. The ones that you write yourself or the ones that come built in to PHP. We will look at both. But first, let's look at the structure of a function. You could see the syntax of a function on the screen here. We have the keyword function, which tells PHP that we are writing a function. Then we have the name of the function. Writing the name of a function follows the same conventions as writing the name of a variable, where we have each word in all lowercase and any spaces are replaced with underscores. We have parentheses, which we'll learn about later. And then we have the opening curly brace, some code, and the closing curly brace. In…
Contents
-
-
-
-
-
(Locked)
What are functions?6m 39s
-
(Locked)
Using functions in WordPress2m 49s
-
(Locked)
Helpful PHP functions6m 17s
-
(Locked)
Writing your own functions7m 2s
-
(Locked)
Challenge: Write your own function to compare two numbers23s
-
(Locked)
Solution: Write your own function to compare two numbers4m 9s
-
(Locked)
-
-