This question already has an answer here:
If I use print
in this code:
<?php
for($i = 1; $i <= 3; print $i . "
") {
$i++;
}
?>
I see as output this:
2
3
4
But when I use echo
the code doesn't work:
<?php
for($i = 1; $i <= 3; echo $i . "
") {
$i++;
}
?>
I see this error:
PHP Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ')' in /media/datos/xampp/htdocs/temp/1.php on line 3
My question is:
- Why can I use
print
as a third expression in afor
loop, but cannot when usingecho
and why do they behave differently from each other?
References:
</div>