php loops how to use a for loop or while loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gmarkrakesh
    New Member
    • Mar 2014
    • 1

    php loops how to use a for loop or while loop

    Hello Everyone

    this is the code
    Code:
    $a=1;
    $b=1;
    while($a<=5)
    {		
    	while($b<=20)
    {
     echo $b
    }
    $b++;
    }
    $a++;
    }
    and i want to print
    1 1
    1 2
    1 3
    1 4
    2 5
    2 6
    2 7
    2 8
    3 9
    3 10
    3 11
    3 12
    4 13
    4 14
    4 15
    4 16
    5 17
    5 18
    5 19
    5 20
    Last edited by Rabbit; Mar 26 '14, 03:26 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • ariful alam
    New Member
    • Jan 2011
    • 185

    #2
    Correct Code

    Hello,
    There are some mistakes in your code. The correct code is below. This will generate correct answer.
    Code:
    $a=1;
    $b=1;
    $i=0;
    while($a<=5){
    	while($i < 4){
    		echo $a . ' ' . $b . '<br/>';
    		$b++;
    		$i++;
    	}
    	$a++;
    	$i = 0;
    }
    Regard

    Happy coding :)

    Comment

    Working...