PHP Functions

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:08
    LEANNA PELHAM: We already know what to write when we want to use
  • 0:11
    some PHP code, how to set a variable and how to print things.
  • 0:15
    Like most languages, PHP also has functions like Rand
  • 0:18
    which gives us a random number.
  • 0:20
    A function always starts with its name
  • 0:22
    followed by opening and closing parentheses.
  • 0:25
    Those are the key and tell PHP that Rand is a function.
  • 0:29
    Think of function like a machine.
  • 0:31
    We execute it with the code you see here and it returns a value.
  • 0:35
    Not all functions work exactly like this, but most do.
Loading ...

PHP Functions

Loading...

We already know what to write when we want to use some PHP code, how to set a variable, and how to print things. Like most languages, PHP also has functions that make it easier to do more complex tasks. Instead of you needing to figure out all of the logic to accomplish something, like randomizing a number, you can just use an existing PHP function, like rand(), to do the work for you. In this lesson, you'll learn how to use a function, what arguments are and how they work, and use some examples in our demo site code.

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