Chapter 5

Using Functions and Session Variables

In This Chapter

arrow Creating functions to manage your code's complexity

arrow Enhancing your code by using functions

arrow Working with variable scope

arrow Getting familiar with session variables

arrow Incorporating session variables into your code

PHP programs are used to solve interesting problems, which can get quite complex. In this chapter, you explore ways to manage this complexity. You discover how to build functions to encapsulate your code. You also learn how to use session variables to make your programs keep track of their values, even when the program is called many times.

Creating Your Own Functions

It won't take long before your code starts to get complex. Functions are used to manage this complexity. As an example, take a look at Figure 5-1.

9781118289389-fg2901.tif

Figure 5-1: This program rolls five dice.

Rolling dice the old-fashioned way

Before I show you how to improve ...

Get HTML5 and CSS3 All-in-One For Dummies, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.