From the course: PHP for WordPress

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Write your own function to compare two numbers

Solution: Write your own function to compare two numbers - PHP Tutorial

From the course: PHP for WordPress

Start my 1-month free trial

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 comparisons, 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 are equal, we'll just send back a. So once we have our result, we could say return result. And then we…

Contents