PHP Loops

Here, you will find Assignments & Exercises related to PHP Loops. Once you learn PHP Loops, it is important to practice on these to understand concepts well.

These PHP Loop exercises contain programs on PHP for Loop, while Loop, mathematical series, and various string pattern designs.

All PHP exercises are available in the form of PHP problem, description and solution. These PHP programs can also be used as assignments for PHP students.

Write a program to count 5 to 15 using PHP loop

Description:
Write a Program to display count, from 5 to 15 using PHP loop as given below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Rules & Hint

  • You can use “for” or “while” loop
  • You can use variable to initialize count
  • You can use html tag for line break

Click below to View Solution/Program


Output:
5
6
7
8
9
10
11
12
13
14
15


Write a factorial program using for loop in php

Description:

Write a program to calculate factorial of a number using for loop in php.

Output:

  The factorial of 3 is 6

Write a program to create Chess board in PHP using for loop

Description:

Write a PHP program using nested for loop that creates a chess board.

Conditions:

  • You can use html table having width=”400px” and take “30px” as cell height and width for check boxes.

Click to View Solution/Program

Output:
Chess-board-in-PHP-using-for-loop


Write a Program to create given pattern with * using for loop

Description:
Write a Program to create following pattern using for loops:

Rules

  • You can use for or while loop
  • You can use multiple (nested) loop to draw above pattern

Click below to View Solution/Program using two for loops

Output:
*
**
***
****
*****
******
*******
********