Why my while loop iteration is 15 times instead of 10?

  foreach, php, while-loop
<?php
$i = 0;
$j = array('U1','U2','U3','U4','U5');
while ($i <= 10) {
    foreach ($j as $value) {
        $i++;
        echo "$i $value <br>";
    }
}

?>

// output
1 U1
2 U2
3 U3
4 U4
5 U5
6 U1
7 U2
8 U3
9 U4
10 U5
11 U1
12 U2
13 U3
14 U4
15 U5

I want my loop iteration is 10 time

Source: Ask PHP

LEAVE A COMMENT