Learn
Introduction to PHP Functions
Review

Great job! Let’s review what we covered in this lesson:

  • We can package a set of instructions within a named function to reuse whenever we’d like.
  • When we invoke a function, the computer will execute the function body, specified by the code block following the parameters list.
  • Functions can return a value by using the return keyword otherwise they return NULL which means no value.
  • We can store the return value of a function in a variable or use it any other way we’d use a value.
  • We can define functions with parameters which are variables we can refer to throughout our function’s body.
  • When invoking functions, the values that we give them are called arguments.
  • Functions can have multiple parameters.
  • The order in which the arguments are passed in decides which parameters they correspond to.
  • You can make an argument optional by providing its corresponding parameter with a default value.
  • If you prepend a parameter with the reference sign (&) that argument will be passed by reference.
  • Variables within functions have local scope and can not be accessed from outside the function.
  • Use the global keyword to use variables from the global scope within a function.

Instructions

Take a look at this diagram of the syntax for defining and calling functions.

Folder Icon

Take this course for free

Already have an account?