PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pilau
Forum Regular
Posts: 594 Joined: Sat Jul 09, 2005 10:22 am
Location: Israel
Post
by pilau » Mon Sep 26, 2005 1:24 pm
Take a look:
Code: Select all
$JSarray .= "events[". $j + 1 ."]={\n";
Now what's wrong with that?
Nathaniel
Forum Contributor
Posts: 396 Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA
Post
by Nathaniel » Mon Sep 26, 2005 1:37 pm
Try:
Code: Select all
$JSarray .= 'events['. ++$j .']={' . "\n";
I think it may not like the the "{\n"...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Sep 26, 2005 1:50 pm
It has to do with the +. Operator precedence dictates that plus, minus and dot operators are processed from left to right within a given statement. Here's an illustration of what's happening
Code: Select all
[feyd@home]>php -r "$j = 2; echo 'foo'.$j+1.'bar';"
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in Command line code on line 1
[feyd@home]>php -r "$j = 2; echo 'foo'.$j;//+1.'bar';"
foo2
[feyd@home]>php -r "$j = 2; echo 'foo'.$j+1;//.'bar';"
1
[feyd@home]>php -r "$j = 2; echo 'foo'.($j+1).'bar';"
foo3bar
pilau
Forum Regular
Posts: 594 Joined: Sat Jul 09, 2005 10:22 am
Location: Israel
Post
by pilau » Mon Sep 26, 2005 1:55 pm
Ok, so it's like math, in general. "Don't forget that braces, are like a concrete wall!" - my math teacher always said.