Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial見綸 陳
6,333 PointsDots be used in the variable
In the conditionals. If the statement is true. We set variable $name = $first_name . ' ' . $last_name
--> What is the function of these two " . " ?
4 Answers
jcorum
71,830 PointsOne of the frustrating things about working in various languages is that sometimes they have different operators for the same thing. As you see from the above answers, concatenation in PHP uses a dot. Concatenation in Javascript, Java, Python, Ruby, however all use the more usual + sign. Concatenation in SQL is the double pipe ||. In Visual Basic and Excel VBA it is &. And there are others! Haskell uses ++.
Putting a + sign for . in PHP, or a . for + in Javascript, are common bugs for web programmers working in both Javascript and PHP.
Grace Kelly
33,990 PointsThe "." in php is called concatenation. This simply allows you to combine or concatenate the two strings together, for example:
<?php
$first_name = "Mike";
$last_name = "The Frog";
echo "Hello". " ". $first_name . " " . $last_name; //outputs "Hello Mike The Frog"
?>
The " " allows you to add a space in between each word.
Hope that helps!!
見綸 陳
6,333 PointsThanks for explain more!
Gianmarco Mazzoran
22,076 PointsHi,
this are concatenation operator here's you find the docs
In your case the .
concatenate the two variables $first_name
and $last_name
with a space between them. The result will be stored in the variable $name
.
here's an example:
<?php
$first_name = "Gianmarco";
$last_name = "Mazzoran";
$name = $first_name . ' ' . $last_name;
// the result of the variable $name will be the concatenation of $first_name and $last_name with a space between them
'Gianmarco Mazzoran'
?>
Hope it helps!
見綸 陳
6,333 PointsThanks for addition document link!!
DICKSON DZOKOTO
1,313 PointsThe function of the two dot is the concatenation variable $first_name and $last_name
見綸 陳
6,333 Points見綸 陳
6,333 PointsThanks for your post.
For someone want to know number operation in php http://php.net/manual/en/language.operators.arithmetic.php