Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying All Items

Iulian Mirzac
Iulian Mirzac
3,083 Points

Illegal string offset 'img'

Hi guys,

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


2 Answers

Ryan S
Ryan S
27,275 Points

Hi Iulian,

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[101] = "Design Patterns";
$catalog[201] = "Forrest Gump";
$catalog[301] = "Beethoven";
$catalog[102] = "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.

Iulian Mirzac
Iulian Mirzac
3,083 Points

Hi Ryan :) Awesome! Thank you a lot. It was right under my nose....