课程: PHP for WordPress (2020)

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Write your own function to compare two numbers

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

课程: PHP for WordPress (2020)

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…

内容