+ 2
Is concatenation not needed in php?
I'm new to php. I usually code in c#.
6 odpowiedzi
+ 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.
+ 3
Thanks. I'll check out the link
+ 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?
+ 2
Thank you
+ 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.
0
the concatenation in php use dot (.) instead of +