steve steve - 5 months ago 10
PHP Question

PHP Multidimentional Array error

We are working on a Monopoly game in PHP as a class project and none of us cab figure this out.
We need to create and use a multidimentional array for the properties in the game. Below is an example of what this looks like.


echo"$stuff --- $arr2[$stuff][9]"; //(this is line 64)

When we try to run this, we get this output.

Notice: Array to string conversation in ... line 64
1 --- Array[9]

Why is it giving us "Array[9]" instead of 60?
Thank you for your time.


Complex array and object expressions need to be wrapped in curly braces {}:

echo "$stuff --- {$arr2[$stuff][9]}";

Or break out of the quotes and concatenate:

echo "$stuff --- " . $arr2[$stuff][9];
echo $stuff . " --- " . $arr2[$stuff][9];

See Variable Parsing - Complex (curly) Syntax.