Saturday, March 15, 2014

Diffrent For Loop Examples for PHP

Eg. 1.
            $space=20;
for($i=1,$k=1;$i<5 ;$i++) //loop for print rows
{
	for($l=1;$l<=$space;$l++)//loop for print space
	
	 	echo '&nbsp;';
	
		$space -=2;
		
		for($j=1;$j<=$i;$j++,$k++) /*loop for print columns*/
		
			echo $k.'&nbsp;';
			echo '<br>';	 
		
 }

       
Output:
                    1 
                  2 3 
                4 5 6 
              7 8 9 10