Introduction to PHP Functions
Lesson 1 of 1
  1. 1

    We can think of programs as series of instructions to be performed by the computer. So far in each of our PHP programs, each step has been explicitly laid out in the order we it to happen. Someti…

  2. 2

    Let’s get right to it and create our first function: […] Let’s walk through the code above: + We used the […] keyword to start our function definition. + We named the function […] . F…

  3. 3

    In our last exercise, we saw that when we define a function, the instructions within the code block aren’t executed. Defining a function only tells the computer to associate a name with a set of in…

  4. 4

    As we build more complicated functions, we’ll often be using them to process data. In order for the data to be useful, functions have the ability to return a value in addition to performing instr…

  5. 5

    The […] keyword immediately stops a function. This means that any code after a […] won’t run. Let’s compare two different functions: “announceRunning()” and “announceRunning2()”. The firs…

  6. 6

    The value returned from a function is just that—a value. This means it can be used in any manner we would normally use a value of that type. This can take some getting used to. Take a look at the f…

  7. 7

    What about functions without […] statements? Any function without a […] returns a special value […] . […] is a special data type that stands for the absence of a value. […] Let’…

  8. 8

    Functions that do exactly the same thing every time they run can save us from having to repeat code in our programs, but functions can do more. In the beginning of this lesson, we wrote a […] …

  9. 9

    We can also define functions with multiple parameters. […] In the function above, we defined the […] function. It takes in two number arguments and returns the result of dividing the firs…

  10. 10

    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 wil…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo