Example 1
for($var=1;$var<=5;print $var,$var++);
//valid
Example 2
for($var=1;$var<=5;echo $var,$var++);
//invalid
the behavior of above two statements is not that straight, could any body explain why they are showing different results ?
Example 1
for($var=1;$var<=5;print $var,$var++);
//valid
Example 2
for($var=1;$var<=5;echo $var,$var++);
//invalid
the behavior of above two statements is not that straight, could any body explain why they are showing different results ?
echo
is a language construct, not a function. It has no return value. print()
is a function, and DOES have a return value.
While both print
and echo
are language constructs, the syntax defined for echo
conflicts with what you are doing. Specifically:
echo 1, 2, 3, 4;
//output: 1234
This conflicts with the syntax for a loop definition, which is why I believe you're not permitted to use echo
there.