CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900 PHP arrays and loops are like peanut butter and jelly; they just go together. It makes your code more readable. Also, I suggest using a for loop rather than what you have there. The below example shows the use of the for loop in PHP. If you don’t know the number iteration to perform over a block of code, you should use the PHP while loop. In the next section, we’ll see how you could use PHP loops with HTML. PHP for loop can be used to traverse set of code for the specified number of times. The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop.In the beginning of each iteration, expr2 is evaluated. Personally though, I prefer to echo HTML when within PHP. For Loops Here’s a PHP For Loop in a little script. When you start to use arrays in HTML5 and CSS3 programming, eventually, you’ll want to go through each element in the array and do something with it. For loop is used because we know how many times loop iterate. These PHP Loop exercises contain programs on PHP for Loop, while Loop, mathematical series, and various string pattern designs. We'll discuss a few flavours of programming loops, but as the For Loop is the most used type of loop, we'll discuss those first. For loop. For loops. This means for loop is used when you already know how many times you want to execute a block of code. inside the for loop we declare if..else condition. Print the sum of odd ans even number separately. PHP Loops . Here, you will find Assignments & Exercises related to PHP Loops. In PHP, it is possible to manage the execution of scripts with different control structures. It should be used if the number of iterations is known otherwise use while loop. PHP Introduction PHP Environment Setup PHP Basics PHP 'echo' and 'print' PHP Variable PHP Superglobal PHP Data type PHP String PHP Operators PHP If..Else..Elseif PHP Switch Statement PHP While loops PHP do..while loop PHP for loops PHP Arrays PHP Function PHP GET and POST Examples & QA PHP Examples PHP Question Answer Advance You can do that by closing your PHP block before the HTML with ?>, and then reopening with