|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-07-29 14:31 UTC] dmitry at rsl dot ru
Description: ------------ comma expression doesn't work outside for operator: this works: <? for($z = $a=2,$b=1;false;); echo "z=$z a=$a b=$b"; ?> this doesn't: <? $z = $a=2,$b=1; echo "z=$z a=$a b=$b"; ?> Parse error: syntax error, unexpected ',' in /home/dmitry/x.php on line 1 Reproduce code: --------------- <? $z = $a=2,$b=1; echo "z=$z a=$a b=$b"; ?> Expected result: ---------------- z=2 a=2 b=1 Actual result: -------------- Parse error: syntax error, unexpected ',' in /home/dmitry/x.php on line 1 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 29 05:00:01 2025 UTC |
How about following examples: while ($a = mysql_fetch_array(),$rec_no++) { } $to_pay = ($left<$total)?($left,$stop=1):$total;Other languages? Let's see: [dmitry@srv dmitry]$ cat x.c; gcc x.c; ./a.out #include<stdio.h> int a,b,c; main() { c = a=1,b=2; printf("a=%d b=%d c=%d\n",a,b,c); } a=1 b=2 c=1 [dmitry@srv dmitry]$ cat x.pl;./x.pl #!/usr/bin/perl $c = $a=1, $b=2; print "a=$a b=$b c=$c\n"; a=1 b=2 c=1 Guess the result of following: <script> c = a=1,b=2; alert('a='+a+' b='+b+' c='+c); </script>