Chapter 3: Controlling Your Code with Conditions and Functions

Chapter 3: Controlling Your Code with Conditions and Functions

Overview

So far you've written some PHP programs that get information from the user, store things in variables, and do some simple operations on those variables. Most of the really interesting things you can do with a computer involve letting it make decisions. Actually, the computer only appears able to decide things. The programmer generates code that tells the computer exactly what to do in different circumstances. In this chapter, you'll learn how to control the flow of a program. Specifically, you'll learn how to:

  • Create a random integer.

  • Use the if structure to change the program's behavior.

  • Write conditions to evaluate variables.

  • Work with the else clause to provide instructions when a condition is not met.

  • Use the switch statement to work with multiple choices.

  • Build functions to better manage your code.

  • Write programs that can create their own forms.