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

PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Creating the Display Function

Dots between code

Hi. Why do we need to put dots between code?

echo "-" . $movie["title"] . "-";

2 Answers

Its because they concatenating operators. when dealing with string elements.

i didnt understand(

you didn't understand what I said or using the "." operator?

I didnt answer what you say

That's cool, lets break it down. I don't know if English is your first language, but these are words in English that if you are programming you should know.

first, concatenation means to join things, or group things together. just like in JavaScript the "+" sign, the "." is for PHP. Remember you can can't use the "+" in PHP like in JavaScript, but they mean the same thing.

here is an example first in JavaScript then in PHP

JavaScript:

var foo = "Hello " + "World" + "!";
//the var foo equals Hello World!

PHP:

<?php

$foo = "Hello " . "World" . "!"; 

// the var foo equals Hello World!

The word operators means what sign of operation you doing. Operators are the signs for addition, subtraction, and other operations like concatenation.

I hope this helps, If you need to dive deeper let me know.

Thank you very much!! But can we use + instead of . ?

NO, you can ONLY use "." in PHP.

mohammed abdi abdulahi warsame
mohammed abdi abdulahi warsame
4,926 Points

but i thing we can just use -comma , - "Hello, world, !" WHAY do we need to use dots

mohammed, I believe we have to use dot . when putting a variable in a string. as in;

    <?php
$earth = "world";
    echo "Hello ".$earth. " and good morning";

    ?>