RE: [PHP] ++$i and $i++ whatz the difference?
| From: | ..s.c.o.t.t.. | Date: | Wed, 28 Feb 2001 11:54:14 +0000 |
| Subject: | RE: [PHP] ++$i and $i++ whatz the difference? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-41968@lists.php.net to get a copy of this message | ||
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:dhaval_adams@yahoo.com]
> Sent: Tuesday, February 27, 2001 23:50
> To: php-general@lists.php.net
> 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: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>