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! While you're at it, check out some resources Treehouse students have shared here.

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

PHP

Ryan O'Connor
Ryan O'Connor
11,282 Points

php multidimension array

I'm trying to retrieve information from one array. I'm getting an Array to String error when I try to access the information inside "topics". On one page I am listing out the topics with .implode. What function do I need to use to access each topic? Then access the individual topic information on another page.

$tracks[] = [
  "topics" => [
    "Physiology" => [
      "media" => [
        "image file name"
      ],
      "paragraphs" => [
        "text"
      ],
    "SA Node and Pacemakers",
    "Atrial Depolarization",
    "Atrio Ventricular Conduction",
    "Ventricular Depolarization",
    "Repolarization",
    "Events at the Cellular Level",
    "Electrodes",
    "ECG Leads and Placement",
  ],
Chris Shaw
Chris Shaw
26,676 Points

Hi Ryan,

I have updated your code formatting which you can learn more about at Posting Code to the Forum.

Is this all of your code? It seems to be missing the key part where you're calling your array values.

1 Answer

This should work, or if it doesn't at least we have better formatting. Basically what happens is your array items such as "SA Node and Pacemakers" etc.. should be within topics array, they are currently in tracks array

$tracks = [
    'topics' => [
       'Psychology' => [
         'media' => [
           'image file name'
         ],
         'paragraphs' => [
           'text',
         ],
       ],
       "SA Node and Pacemakers",
       "Atrial Depolarization",
       "Atrio Ventricular Conduction",
       "Ventricular Depolarization",
       "Repolarization",
       "Events at the Cellular Level",
       "Electrodes",
       "ECG Leads and Placement",
    ],
  ];