Jump to content

begginer 1 line of code. Just to have better understanding


hansolo

Recommended Posts

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

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...