From the course: PHP with MySQL Essential Training: 2 Build a CMS

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Use an option for conditional code

Use an option for conditional code

- [Instructor] In this movie, we will use an array of options with some of our functions to allow them to change their default behavior. Let me give you an example. Let's say we want to modify the behavior of our find all subjects function. We can pass in an argument to the function and then make the function, respond to that argument. A good way to do this is to pass in an array of options instead of a single argument. That way we can easily add other options by adding to the array, but the argument list does not grow and become hard to manage. So you can see here, I'm passing in options, I've got a default value, which is an empty array. So it is optional, we don't have to have anything sent in, but if we do, we can pass it an associate of array and we can respond to the values that are in that array. You can see here in my code, I'm checking the options to see if there is an option for visible. And if there is, I'm setting the variable visible to it, I'm also using the double…

Contents