Optional PHP Function Arguments

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:03
    Optional PHP Function Arguments with Leanna Pelham
  • 0:08
    But right now, the contact page is broken
  • 0:11
    because get_pets has a required argument
  • 0:14
    and we're not passing it anything.
  • 0:17
    But what should we pass here?
  • 0:19
    One thousand? One million?
  • 0:22
    We really want no limit,
  • 0:24
    but that's not possible right now,
  • 0:26
    so let's be clever and pass zero.
  • 0:29
    Next, add an if statement in get_pets.
Loading ...

Optional PHP Function Arguments

Loading...

In this tutorial we're going to add our $limit variable as an optional argument to our get_pets() function. We're using this variable in our if statement, and we're going to look at different ways to supply "true" and "false" using data other than booleans. This allows you to pass in a value and still evaluate true/false. PHP has some conventions for what is true or not, and it's a good idea to understand what these are.

Downloads: 
Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.