You are here: Re: $i++ problem understanding « PHP Language « IT news, forums, messages
Re: $i++ problem understanding

Posted by Hilarion on 11/17/08 11:29

>>> But much harder to accept is and I fail to see the logic in it,
>>> is the following :
>>> $i = 1;
>>> print($i++);
>>> This will print 1 and only afterward will the value of $i be increased
>>> by 1. It is between (), so logic tells me first $i++ and then print.
>>> [snip]
>>
>> print is a language construct, not actually a function. That means that
>> the parentheses are optional.
>> [snip]
>
> My two cents:
> Post-increment operator does incrementation after the whole instruction
> (which contains it) is executed, not after the expression containing it
> is executed, so it does not matter if you are using some language construct
> like "print" or "echo" or some function or expressions with different
> operator priority and parentheses.
>
> Example:
>
> some_function(($i++ * 2) + 4) | 7);
>
> is equivalent to:
>
> some_function(($i * 2) + 4) | 7); $i += 1;
>
>
> Example for pre-increment operator:
>
> some_function((++$i * 2) + 4) | 7);
>
> is equivalent to:
>
> $i += 1; some_function(($i * 2) + 4) | 7);


I was wrong when I was writing it. If you are reading this post (possibly
in some newsgroup archives), then read the post by Chung Leong in this thread.
He described the operator correctly.


Hilarion

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация