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


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



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

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