aeonsky Posted June 7, 2008 Share Posted June 7, 2008 Hey everyone! I'm very familiar with PHP, but I've recently bought "Learning PHP5" from Amazon, to make sure I got the most basic stuff memorized. I have two problems that they don't explain in the book... 1. Auto-increment a variable by 1 I have always did it as: $i++; But in the book they do it: ++$i; Is one preferred over the other, because maybe one is deprecated, or either one is fine? 2. The -> operator They use the -> operator in the PHP scripts, but do not explain what it does. Thank you!~ Link to comment https://forums.phpfreaks.com/topic/109074-two-simple-questions/ Share on other sites More sharing options...
DarkWater Posted June 7, 2008 Share Posted June 7, 2008 1)There is a major difference. ++$i; increases $i BEFORE evaluating expressions, and $i++ does it after. Example: $i = 5; $b = $i++; //$i = 6, $b = 5 $i = 5; $b = ++$i; //$i = 6, $b = 6 2) -> is used to reference methods and properties of objects. Link to comment https://forums.phpfreaks.com/topic/109074-two-simple-questions/#findComment-559573 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.