Can someone tell me why the output of echo
of this Code is 13?
$a=10;
$b=2;
$j=$a/2;
for ($i=0;$i<$j;$i++){
if ($i % $b == 1)
echo "$i";
}
Can someone tell me why the output of echo
of this Code is 13?
$a=10;
$b=2;
$j=$a/2;
for ($i=0;$i<$j;$i++){
if ($i % $b == 1)
echo "$i";
}
Try this
<?php
$a=10;
$b=2;
$j=$a/2;
echo $j;
echo "<br>";
for ($i=0;$i<$j;$i++){
if ($i % $b == 1)
echo "$i";
echo "<br>";
}
?>
when start loop then $i start from 0 loop have max 5 loops from 0 to 4 so
$a=10;
$b=2;
$j=$a/2; //which will be 5
for ($i=0;$i<$j;$i++){ //the loop executes 5 times
if ($i % $b == 1) // this condition satisfies when $i becomes 1 && 3
echo "$i"; //1 and 3 will be printed.
}
Check The comments written in your code
I hope that will help you understand how your code works.
$a=10;
$b=2;
$j=$a/2;
for ($i=0;$i<$j;$i++){
if ($i % $b == 1)
echo "output";
echo "$i";
}