Basic Addition Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Basic Addition Question

Post by tecktalkcm0391 »

What is the difference between $i++ and ++$i when used in a for loop?

Thanks!
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Basic Addition Question

Post by Mark Baker »

Code: Select all

 
$i = 1;
$x = $i++;
//  $x = 1
//  $i = 2
 
$i = 1;
$x = ++$i;
//  $x = 2
//  $i = 2
 
http://www.php.net/manual/en/language.o ... rement.php

Significance in a loop is no different to usage anywhere else
Post Reply