课程: PHP for WordPress (2020)

今天就学习课程吧!

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

Writing your own functions

Writing your own functions

- [Instructor] Now that you know a bit about functions, let's walk through writing our own. Something that can actually work in a real program instead of just in the abstract. The function that we're going to write is going to detect if a string is a palindrome. A palindrome is a string that reads the same backwards and forwards. This will allow us to accomplish a few objectives. Create a Boolean function, pass an argument to that function and use some built in PHP functions. Let's get started. So we'll start by using the function keyword and since this is going to be a Boolean function, we're going to call it is palindrome. And it's going to accept one argument and we will call that argument string. We'll add our curly braces and then we'll do the check. Now the simplest way to do a check for a palindrome is to reverse the string and luckily there is a built in PHP function to do that. So let's create a variable called…

内容