13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Next<br />

57<br />

For example, the code<br />

if ($totalqty == 0) {<br />

echo "You did not order anything on the previous page!";<br />

exit;<br />

}<br />

could be converted to this alternative syntax using the keywords if <strong>and</strong> endif:<br />

if ($totalqty == 0) :<br />

echo "You did not order anything on the previous page!";<br />

exit;<br />

endif;<br />

Using declare<br />

One other control structure in <strong>PHP</strong>, the declare structure, is not used as frequently in<br />

day-to-day coding as the other constructs.The general form of this control structure is as<br />

follows:<br />

declare (directive)<br />

{<br />

// block<br />

}<br />

This structure is used to set execution directives for the block of code—that is, rules about<br />

how the following code is to be run. Currently, only one execution directive, called<br />

ticks, has been implemented.You set it by inserting the directive ticks=n. It allows<br />

you to run a specific function every n lines of code inside the code block, which is principally<br />

useful for profiling <strong>and</strong> debugging.<br />

The declare control structure is mentioned here only for completeness. We consider<br />

some examples showing how to use tick functions in Chapters 25,“Using <strong>PHP</strong> <strong>and</strong><br />

<strong>MySQL</strong> for Large Projects,” <strong>and</strong> 26, “Debugging.”<br />

Next<br />

Now you know how to receive <strong>and</strong> manipulate the customer’s order. In the next chapter,<br />

you learn how to store the order so that it can be retrieved <strong>and</strong> fulfilled later.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!