I'm having problems formatting arrays and nested arrays with print function in PHP.
So far into learning PHP, I have been wrapping print commands with " "
and putting basic html like <p>
within the quotes with the single variables, and everything works fine. Today I have been creating arrays and nested arrays and have been getting some strange behaviour.
For instance:
// nested array
$array2 = array(6, "fox", "dog", array("x", "y", "z"));
// display nested array index 1
print "<p> $array2[3][1] </p>";
This prints Array[1]
instead of y
.
If I do this it prints ok:
print "<p>" . $array2[3][1] . "</p>";
The last array I am trying to get to print using a print readible with <pre>
tags. So far I have tried this, but all I see in the browser is just array
print_r("<pre>" . $array2 . "</pre>");
I must be doing something wrong if the tags will not concat?
{$array2[3][1]}
"` – AbraCadaver Oct 21 '14 at 15:43