types - Increment behavior on strings - PHP easter egg? -
$var = 'test_1'; var_dump(++$var); // string(6) "test_2" $var2 = '1_test'; var_dump(++$var2); // string(6) "1_tesu" $var3 = 'test_z'; var_dump(++$var3); // string(6) "test_a" $var4 = 'test_'; var_dump(++$var4); // string(5) "test_"
so apparently, using increment operator on string has effect of increasing digit if last character number, increasing letter , resetting once z if last character in alphabet, , has no effect on non alpha numeric characters.
is standard feature, expected in many scripting languages, or did find php easter egg?
php follows perl's convention when dealing arithmetic operations on character variables , not c's. example, in php , perl $a = 'z'; $a++; turns $a 'aa', while in c = 'z'; a++; turns '[' (ascii value of 'z' 90, ascii value of '[' 91). note character variables can incremented not decremented , plain ascii characters (a-z , a-z) supported. incrementing/decrementing other character variables has no effect, original string unchanged.
-> http://php.net/manual/en/language.operators.increment.php
Comments
Post a Comment