1.7. Saving Data for Later

Often it is necessary to save information for later use. PHP, like most programming languages, offers the concept of variables. Variables give a name to the information you want to save and manipulate. Listing 1.8 expands on our example by using variables (see Figure 1.2).

Figure 1.2. Output from Listing 1.8.

The first block of PHP code puts values into some variables. The four variables are YourName, Today, CostOfLunch, and DaysBuyingLunch. PHP knows they are variables because they are preceded by a dollar sign ($). The first time you use a variable in a PHP script, some memory is set aside to store the information ...

Get Core PHP Programming, Third 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.