From the course: Learning PHP

Unlock the full course today

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

Writing custom functions

Writing custom functions - PHP Tutorial

From the course: Learning PHP

Start my 1-month free trial

Writing custom 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. We're going to use one of my favorite examples from when I was in school and that is detecting if a string is a palindrome, that 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 built in PHP functions. Let's get started. So we'll write our opening PHP tag, and then we will name the function. We'll use the keyword function and we'll call this is palindrome. Since this is going to be a Boolean function, it's always good to name those functions the question they're answering. So this is answering is the string we're passing a palindrome? And then it's going to accept some string, which we will call string. Now the…

Contents