Chapter 7. PHP Building Blocks for Programs
In This Chapter
Echoing output to Web pages
Assigning values to variables
Stopping and breaking out of programs
Creating and using arrays
Using conditional statements
Building and using loops for repeated statements
Using functions
PHP programs are a series of instructions in a file named with an extension that tells the Web server to look for PHP sections in the file. (The extension is usually .php
or .phtml
, but it can be anything that the Web server is configured to expect.) PHP begins at the top of the file and executes each instruction, in order, as it comes to it. Instructions are the building blocks of PHP programs.
The basic building blocks are simple statements — a single instruction followed by a semicolon. A simple program consists of a series of simple statements. For example, the Hello World program in Chapter 6 is a simple program. However, the programs that make up a Web database application aren't that simple. They're dynamic and interact with both the user and the database. Consequently, the programs require more complex building blocks.
Here are some common programming tasks that require complex building blocks:
Storing groups of related values together: You often have related information, such as the description, picture, and price of a product or a list of customers. Storing this information as a group that you can access under one name is efficient and useful. This PHP feature is an array.
Setting up statements that execute only ...
Get PHP and MySQL® For Dummies®, 4th 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.