From the course: PHP for WordPress

Unlock the full course today

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

Writing your own functions

Writing your own functions - PHP Tutorial

From the course: PHP for WordPress

Start my 1-month free trial

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…

Contents