Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
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,276 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.