Let’s say I have this following code:
<?php
$i = 1;
$user_login = "some_name";
do {
$user_login_tmp = $user_login . "_" . ($i++);
echo $user_login_tmp . "\n";
} while ($i<10);
?>
As seen in this demo(clickable!), the first echo echoes some_name_1.
This seems kinda weird to me since there is $i++ there.
How come that the first output isn’t ..._2? Am I missing something?
I tried looking for an answer in the PHP manual page of the do-while loop but I couldn’t find my answer there…
$i++Post-increments, it means:return $i and then increments $i by one.The demo’s output will start with
..._2if you change the code to(++$i)(new demo)Check out the PHP.net’s page about the incrementing operator:
http://php.net/manual/en/language.operators.increment.php