How to add digits of a numeric series

We can print a numeric pyramid series and also can print the sum of every row using php code. We need two ‘for’ loops to print this pattern in php. First ‘for’ loop is used for rows and second ‘for’ loop is used for numbers in a row. We use ‘if’ conditions to add a ‘+’ sign between the numbers also some variables to store the sum of a row.

$k=1; $b=0;
for($i=1; $i<=5; $i++){
  for($j=1; $j<=$i; $j++){
		echo "+";
		echo $j;
	$a=$j - 1;
	$b=$a + $b;
	echo "=".$b;
	echo "<br>";

Leave a Reply