Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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";

    ?>