+ 2
The code in the description is working in playground where as it should not because it has mistakes...plz tell me why
<?php $myArray[0] = "John"; $myArray[1] = "<strong>PHP</strong>"; $myArray[2] = 21; echo "$myArray[0] is $myArray[2] and knows $myArray[1]"; ?>
6 Respostas
+ 5
Because in Php string in double quotes are interpreted: if they contains variable names, they are replaced by their value, so your last line is equivalent to:
echo $myArray[0]." is ".$myArray[2]." and knows ".$myArray[1];
+ 3
Your question, and almost your problem, is unclear: it works as it should in sololearn code playground... have you problem with trying to use it elsewhere?
+ 3
( btw i did not write this code, it is an example code from arrays exercise of php course )
+ 2
why the variable myArray[0] is inside double quote, i thought only strings need double quotes
+ 2
It's echoing a string. That's what echo does.
+ 2
dot should be used for string concatenation
and the array value place without double quotation
only the string part must be in double quotation