Jump to content

Two simple questions!


aeonsky

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.