one is post-increment, and one is pre-increment:
POST-increment ($i++)
$i = 1;
print $i++;
print "\n"
print $i;
prints :
1
2
becuase $i is printed out and *then* it is incremented, so
the next print statement prints out the incremented value,
not the print $i++; statement
PRE-increment (++$i)
$i = 1;
print ++$i;
print "\n"
print $i;
prints :
2
2
becuase $i is incremented, and *then* printed out.
> -----Original Message-----
> From: Dhaval Desai [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 27, 2001 23:50
> To: [EMAIL PROTECTED]
> Subject: [PHP] ++$i and $i++ whatz the difference?
>
>
> Hi!
>
> I have a simple question. Please see the code below:
>
> <?php
>
> for($i=0; $i<=10; $i++)
> {
> echo "$i<br>";
>
> }
> ?>
>
> Now, See this code:
>
> <?php
>
> for($i=0; $i<=10; ++$i)
> {
> echo "$i<br>";
>
> }
> ?>
>
> I get the same out put from both the Scrits. What's
> the difference then anywayz?
>
>
> Thank You!
> Dhaval Desai
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]