PHP: Using $count++ in an if condition
conditional-statements, loops, php
Solution
- $count++ is a post-increment. That means that it will increment after the evaluation.
- ++$count is a pre-increment. That means that it will increment before the evaluation.
http://www.php.net/manual/en/language.operators.increment.php
To answer your question, that is perfectly valid, just keep in check that your value will be 2 after the if has been done.
Problem
I'm wondering if the $count++ way of incrementing a counter is okay to use in a conditional statement? Will the variable maintain it's new value? ``` $count = 0; foreach ($things as $thing){ if($count++ == 1) continue; ... } ```