Re: $i++ problem understanding
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: $i++ problem understanding

From: Thomas Venus <venus@wm-schmuck.de>
Date: Wed Oct 05 2005 - 11:48:18 CEST

$a++
always means: use the OLD value and AFTER that add one
in some other languages there is the ++a expression which means add
first the use the result; don't know if that can be done in php
Greets
Thomas
 

-- 
Pugi! wrote:
> Currently I am studying PHP.
> 
> I can understand the following :
> $a = 10;
> $b = $a++;
> print("$a, $b");
> will print 11, 10 on the screen.
> because when $b = $a++ first thing that happens is $b = $a
> and then $a = $a + 1. I am willing to and can accept that.
> 
> 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.
> 
> Can anyone help me understand this or see the logic in it ?
> 
> 
> thanx,
> 
> Pugi!
Received on Tue Oct 18 02:32:08 2005