this code is to sum up 1 to 10 using the arithmetic progression
The output should be as 550 code:
<?php
$total = 0;
for ($i = 1; $i <= 10; $i++) {
for ($j = 10; $j >=1 ; $j++) {
$total = $i + $j;
break;
}
}
$total = $total / 2;
print $total."<br/>";
?>
Current output: 10 Expected output: 550
and In second case I have
<?php
$list = [1, 2, 3, 4];
foreach ($list as $row)
{
switch ($row)
{
case 1:
print "This is One
";
case 2:
print "This is Two
";
case 3:
print "This is Three
";
}
}
print "
";
?>
Current output: This is One This is Two This is Three This is Two This is Three This is Three
Expected output: This is One This is Two This is Three This is Four
In my first code I want to get 550 through first program but when I run it throw wrong output i.e 122666133 and in case of second program current program throw wrong output but expected output as I mention above. So, How can I fix this issue ?Please help me.
Thank You