Page 1 of 1

Basic Addition Question

Posted: Sun Oct 11, 2009 4:36 pm
by tecktalkcm0391
What is the difference between $i++ and ++$i when used in a for loop?

Thanks!

Re: Basic Addition Question

Posted: Sun Oct 11, 2009 4:43 pm
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