Q&A

Q1: Must a control structure’s test expression result in a Boolean value?
A1: Ultimately, yes. However, in the context of a test expression, zero, an undefined variable, or an empty string is converted to false for the purposes of the test. All other values evaluate to true.
Q2: Must I always surround a code block in a control statement with brackets?
A2: If the code you want executed as part of a control structure consists of only a single line, you can omit the brackets. The code examples in this book retain brackets to promote readability. Retaining the brackets for single-line control statements can also help guard against bugs as new lines are added to the block over time.
Q3: Does this hour cover every kind of loop there is?

Get Sams Teach Yourself PHP in 24 Hours, 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.