Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Basic Control Structures in PHP

By Darren W. Hedlund
2005-06-20


Notes on embedding code blocks

When writing programs, it is often common to embed conditions, or even other loops, within other loops or conditionals. For example, the following will count from 1 to 5 but display the string "Magic Number!" before it displays the number 3:

<?php $count = 1; while($count <= 5) { if($count == 3) { echo "Magic Number!<br />"; } echo $count."<br />"; $count++; } ?>

This feature is an important part of the language and is used quite frequently; it can be used in any syntax where a code block (distinguished by the { and } symbols) exists.



Tutorial Pages:
» Conditional blocks
» The if statement
» Basic looping
» The while statement
» Infinite loops
» Notes on embedding code blocks


 | Bookmark
Related Tutorials:
» Zend Framework Tutorial
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1

Ask A Question
characters left.