Welcome to the Treehouse Community
Looking to learn something new?
Iulian Mirzac3,083 Points
Illegal string offset 'img'
I am trying to display elements from data.php to catalog.php. When loading the page it says: Warning: Illegal string offset 'img' in /home/treehouse/workspace/catalog.php on line 42 Warning: Illegal string offset 'title' in /home/treehouse/workspace/catalog.php on line 43
It looks as in the course but something is not right since it's not working. I have triple checked the code.
Here's the snapshot: https://w.trhou.se/24h27kkhqf
Ryan S27,275 Points
The issue is that you forgot to remove the previous
$catalog array that was defined a couple videos back when Alena created the "data.php" file.
In "catalog.php" you will need to remove the following lines of code near the top of your file:
$catalog = array(); $catalog = "Design Patterns"; $catalog = "Forrest Gump"; $catalog = "Beethoven"; $catalog = "Clean Code";
This array does not have the named keys that are required in your
foreach loop, but the new data file does. The problem is that you are overwriting the array immediately after including it.