By Matt Butcher
tips and tricks
a++: Using PHP strings in unusual ways
Submitted by matt on Sun, 2009-02-22 15:40Here's a PHP question for you: When the following code is executed, what will the output be (or will the code fail)?
<?php $char = 'a'; print ++$char . PHP_EOL; ?>
The answer: The above will print a single line.
b
The reason for this is that an increment operation on a string increments the letter. In short, it treats strings (in this context) more like a char type as in C or Java. Well, it treats them sorta like a char. PHP has some special... behaviors when it comes to strings and incrementing operations. In this article, I'll show some of those behaviors.








Recent comments
19 hours 11 min ago
22 hours 40 min ago
1 day 4 hours ago
1 day 4 hours ago
1 day 4 hours ago
1 day 4 hours ago
1 day 16 hours ago
1 day 21 hours ago
1 day 22 hours ago
1 day 22 hours ago