note 115889 added to language.operators.increment

From: Date: Fri, 10 Oct 2014 09:27:30 +0000
Subject: note 115889 added to language.operators.increment
Groups: php.notes 
Request: Send a blank email to php-notes+get-200616@lists.php.net to get a copy of this message
Regarding character incrementing and PHP following Perl's convention with character operations. Actually i found that there is a difference, and incrementing and decrementing unfortunately does not yield the reverse, expected results. For example, the following piece of code: <?php echo '== Alphabets ==' . PHP_EOL; $s = 'W'; for ($n=0; $n<10; $n++) { echo ++$s . ' '; } echo PHP_EOL; for ($n=10; $n>0; $n--) { echo (--$s) . ' '; } ?> Will output: == Alphabets == X Y Z AA AB AC AD AE AF AG AG AG AG AG AG AG AG AG AG AG Please note that the decrement operator has no effect on the character or string. On the other hand, in Perl, the similar script: #!/usr/bin/perl my $s = 'W'; foreach (1 .. 10) { print ++$s . " "; } print "\n"; foreach (1 .. 10) { print --$s . " "; } Will output: X Y Z AA AB AC AD AE AF AG -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 ---- Server IP: 72.52.91.14 Probable Submitter: 188.25.246.88 ---- Manual Page -- http://php.net/manual/en/language.operators.increment.php Edit -- https://master.php.net/note/edit/115889 Del: integrated -- https://master.php.net/note/delete/115889/integrated Del: useless -- https://master.php.net/note/delete/115889/useless Del: bad code -- https://master.php.net/note/delete/115889/bad+code Del: spam -- https://master.php.net/note/delete/115889/spam Del: non-english -- https://master.php.net/note/delete/115889/non-english Del: in docs -- https://master.php.net/note/delete/115889/in+docs Del: other reasons-- https://master.php.net/note/delete/115889 Reject -- https://master.php.net/note/reject/115889 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200616) next »