Reference — What does this symbol mean in PHP?

Web Technologies Web Development 3 years ago

3.01K 1 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago
_x000D_ Incrementing / Decrementing Operators ++ increment operator -- decrement operator Example Name Effect --------------------------------------------------------------------- ++$a Pre-increment Increments $a by one, then returns $a. $a++ Post-increment Returns $a, then increments $a by one. --$a Pre-decrement Decrements $a by one, then returns $a. $a-- Post-decrement Returns $a, then decrements $a by one. These can go before or after the variable. If put before the variable, the increment/decrement operation is done to the variable first then the result is returned. If put after the variable, the variable is first returned, then the increment/decrement operation is done. For example: $apples = 10; for ($i = 0; $i < 10; ++$i) { echo 'I have ' . $apples-- . " apples. I just ate one.\n"; } Live example In the case above ++$i is used, since it is faster. $i++ would have the same results. Pre-increment is a little bit faster because it really increments the variable and after that 'returns' the result. Post-increment creates a special variable, copies there the value of the first variable and only after the first variable is used, replaces its value with second's. However, you must use $apples--, since first, you want to display the current number of apples, and then you want to subtract one from it. You can also increment letters in PHP: $i = "a"; while ($i < "c") { echo $i++; } Once z is reached aa is next, and so on. Note that character variables can be incremented but not decremented and even so only plain ASCII characters (a-z and A-Z) are supported. Stack Overflow Posts: Understanding Incrementing
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum


Q

Unity hosting a custom piece of code on own website [on hold]

_x000D_ _x000D_ I was wondering how would you be able to host an "API" on your own website that you...
Q

I am needing advice on a web bot [on hold]

_x000D_ _x000D_ I want to code a bot that has a GUI or CLI doesn't really matter yet but a GUI would...
Q

date and time picker, that can take a max and min absolute time, compatible with react [on hold]

_x000D_ _x000D_ I have an issue with scheduling things in a web platform (react.js), and need a date...

Important Web Technologies Links