Is concatenation not needed in php? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

Is concatenation not needed in php?

I'm new to php. I usually code in c#.

5th Jul 2017, 8:00 AM
Shaina
Shaina - avatar
6 Respostas
+ 6
@Shaina, yes it's correct. It's called "string interpolation": https://en.wikipedia.org/wiki/String_interpolation Notice that you must use double quotation mark in this case.
5th Jul 2017, 9:12 AM
BĆ ng Tį»© CĘ°į»ng
BĆ ng Tį»© CĘ°į»ng - avatar
+ 3
Thanks. I'll check out the link
5th Jul 2017, 9:16 AM
Shaina
Shaina - avatar
+ 2
Yes I know that. Sorry šŸ™ˆ I forgot to add the code I wanted to discuss. The code is: <?php $myArray[0]= "John"; $myArray[1]= "<strong>PHP</strong>" $myArray[2]= 21; echo "$myArray[0] is $myArray[2] and knows $myArray[1] //Outputs "John is 21 and knows PHP" ?> This was the code in one of the lessons. I wanted to know if it is correct?
5th Jul 2017, 8:27 AM
Shaina
Shaina - avatar
+ 2
Thank you
5th Jul 2017, 8:52 AM
Shaina
Shaina - avatar
+ 1
yes you can use directly or concatenating: echo "$myarr[0] is $myarr[2] and knows $myarr[1]"."<br>"; echo $myarr[0] . "is" . $myarr[2] . "and knkows " . $myarr[1]; both are giving same result.
5th Jul 2017, 8:50 AM
Peshkawt Mahmood
Peshkawt Mahmood - avatar
0
the concatenation in php use dot (.) instead of +
5th Jul 2017, 8:14 AM
Peshkawt Mahmood
Peshkawt Mahmood - avatar