Hi everyone,
While studying PHP, I came across two codes that have the same result.
However, there is a line in the second example,echo $i;
, that I could not understand its usefulness.
Besides, when I delete that line and change $i++
to echo $i++
the code produces the same result.
The code is from www.php.net
Here is a link to the lesson
<?php
/* example 1 */
$i = 1;
while ($i <= 10) {
echo $i++; /* the printed value would be
$i before the increment
(post-increment) */
}
/* example 2 */
$i = 1;
while ($i <= 10):
echo $i;
$i++;
endwhile;
?>
In short, why don’t we do this in the second example:
<?php
/* example 2 */
$i = 1;
while ($i <= 10):
echo $i++;
endwhile;
?>