Increment and Decrement of a string in PHP

<?php
$string = 'abc';

echo $string; // outputs abc

$string++;

echo $string; // outputs abd

$string++;

echo $string; // outputs abe

++$string;

echo $string; // outputs abf

++$string;

echo $string; // outputs abg

$string--;

echo $string; // outputs abg

$string--;

echo $string; // outputs abg

--$string;

echo $string; // outputs abg

--$string;

echo $string; // outputs abg

/* Decrement operator doesn't have any effect on string but increment operator increases the last character of the string. If we use increment operator when the last character of a string is Z or, z then the the last character will be A or, a respectively. */
?>

Comments

Popular posts from this blog

Timus 1209. 1, 10, 100, 1000... accepted solution in C

Timus Problem 1086. Cryptography Accepted Solution in C

Timus 1083. Factorials!!! Accepted Solution in C