note 56433 added to language.operators
| From: | rick at nomorespam dot fourfront dot ltd dot uk | Date: | Fri, 02 Sep 2005 10:51:21 +0000 |
| Subject: | note 56433 added to language.operators | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94655@lists.php.net to get a copy of this message | ||
A quick note to any C developers out there, assignment expressions are not interpreted as you may
expect - take the following code ;-
<?php
$a=array(1,2,3);
$b=array(4,5,6);
$c=1;
$a[$c++]=$b[$c++];
print_r( $a ) ;
?>
This will output;-
Array ( [0] => 1 [1] => 6 [2] => 3 )
as if the code said;-
$a[1]=$b[2];
Under a C compiler the result is;-
Array ( [0] => 1 [1] => 5 [2] => 3 )
as if the code said;-
$a[1]=$b[1];
It would appear that in php the increment in the left side of the assignment is processed prior to
processing the right side of the assignment, whereas in C, neither increment occurs until after the
assignment.
----
Manual Page -- http://www.php.net/manual/en/language.operators.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56433
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56433&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56433&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56433&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56433&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56433&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56433&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56433&report=yes
Search -- http://master.php.net/manage/user-notes.php