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.
Solution: Write your own function to compare two numbers
From the course: PHP for WordPress
Solution: Write your own function to compare two numbers
(upbeat music) - [Instructor] All right, let's write this solution for the previous challenge. First we'll start off with the keyword function. I'm going to call this "Compare Numbers", and then it's going to accept two arguments. I will call them A and B. We'll add our curly braces. Now it's time to do the comparison. So I think the most obvious way to do this would be to maybe create a variable called "Result". We'll just call this "False" for now. And then we do the comparison. So we say if A is greater than B, then result gets A, else if B is greater than A, then result gets B, else, don't forget the semicolon. In this case, if A is not greater than B and B is not greater than A, they are equal. So we would say result is, and since we just need to send back the bigger number and we're not making any note of if they're equal, we'll just send back A. So once we have a result, we could say, return result. And then we could test this by saying, we'll use print R for this one. Compare…
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)
-
-