RE: [PHP] Simple: Whats wrong with this?
| From: | Chris W. Parker | Date: | Wed, 17 Mar 2004 17:09:05 +0000 |
| Subject: | RE: [PHP] Simple: Whats wrong with this? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-180700@lists.php.net to get a copy of this message | ||
Jake McHenry <mailto:linux@nittanytravel.com>
on Wednesday, March 17, 2004 9:01 AM said:
> Does this always work? In my timesheet app, I have to do $counter =
> $counter + 1, because for some reason the $counter++; doesn't work.
> It just doesn't work, no incrementation of the variable. Is there
> something in php.ini that can prohibit this from working?
$var++ is a post incrementer meaning the value is updated at the next
command*.
++$var is a pre increment meaning the value is updated immediately.
is it possible you are expecting the results of ++$var?
try this and see what happens:
<?php
$var = 2;
echo $var++ . "<br>";
echo ++$var . "<br>";
?>
also, i don't know of anything in the php.ini that would turn this short
hand off. seems unlikely that there is.
chris.
* i'm not exactly sure how the compiler determines when to post
increment, but i think i'm correct.