hansolo Posted June 18, 2010 Share Posted June 18, 2010 I would like to understand the code below. I think "$echoString" is a variablewhat does the dot and equals sign mean in php .=$echoString .="&player".$i."=".$row['player']."&score".$i."=".$row['score']; Link to comment Share on other sites More sharing options...
jeffman Posted June 18, 2010 Share Posted June 18, 2010 The dot operator is used to concatenate (add) strings. Many other languages just use the + operator. It works like this:$str1 = "Hi";$str2 = ", Bob";echo $str1 . $str2; // prints "Hi, Bob"Most math-type operators can be combined with an assignment operator ( the = sign). It's a shortcut to writingsomething = itself (operator) something_elseSo $str1 .= $str2;is the same as writing:$str1 = $str1 . $str2;Soecho $str1; // prints "Hi, Bob" Link to comment Share on other sites More sharing options...
thescientist Posted June 18, 2010 Share Posted June 18, 2010 its adding those string values and variables to the current value of $echoString. In javascript, for example you would see it as +=.For instance: $x = 1;$x .= 4;//value of $x is now 5 basically . is how you add/concatenate in PHP.edit: edited example to use PHP instead of JS syntax Link to comment Share on other sites More sharing options...
Ingolme Posted June 18, 2010 Share Posted June 18, 2010 Edit: Ouch, looks like I was a little slow typing the answer and people got ahead of me.In PHP and Javascript, certain operators can be prepended to the = operator.This is equivalent to operating a value with itself as in the following examples.Concatenation:$str = $str . "something";$str .= "something"Addition:$x = $x + 5;$x += 5;I'm quite sure the PHP tutorial on W3Schools should have those operators explained. Link to comment Share on other sites More sharing options...
hansolo Posted June 19, 2010 Author Share Posted June 19, 2010 how would i put a space? were would i place the <br> tag . not that i need to but it will help for future projects $str1 = "string1";$str2 = "string2";$str1 .= $str2;echo $str1; Link to comment Share on other sites More sharing options...
jeffman Posted June 19, 2010 Share Posted June 19, 2010 FWIW:Actionscript is based on ECMAScript, which is the parent language of JavaScript. (Historically, ECMAScript was first derived from JavaScript, but the Standards people decided to treat ECMAScript as the standard, and now languages like JavaScript and Actionscript and a few others are all considered "dialects" of ECMAScript.)JavaScript and PHP belong to the "C-family" of languages, meaning languages that use the same conventions as C. The syntactic pattern we are describing has been central to C since the language was created back in the early 1970s. Link to comment Share on other sites More sharing options...
jeffman Posted June 19, 2010 Share Posted June 19, 2010 Wow. Changing posts.It looks like you have an orphaned } character just sitting there doing nothing. Unless there is more code than you have shown, simply remove it. If you really want to test the concatenation, remove the mySQL stuff also. Link to comment Share on other sites More sharing options...
hansolo Posted June 19, 2010 Author Share Posted June 19, 2010 Wow. Changing posts.It looks like you have an orphaned } character just sitting there doing nothing. Unless there is more code than you have shown, simply remove it. If you really want to test the concatenation, remove the mySQL stuff also.yes sorry for changing posts . when i posted. I tried to solve the error as well at the same time . I found the culprit it was the open bracket } Link to comment Share on other sites More sharing options...
thescientist Posted June 21, 2010 Share Posted June 21, 2010 how would i put a space? were would i place the <br> tag . not that i need to but it will help for future projects $str1 = "string1";$str2 = "string2";$str1 .= $str2;echo $str1;to add HTML to be outputted along with PHP, you could do something like this:echo $str1 . '<br/>'; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.