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

Boris Kamp
Boris Kamp
16,660 Points

array or object

Hi guys, Im kinda lost here. I need to create something like this:

$tabs = array
                (
                    array( 'id' => 'reviews', 'form_id' => '1'),
                    array( 'id' => 'showcases', 'form_id' => '1'),
                    array( 'id' => 'tipsandtricks', 'form_id' => '1'),
                    array( 'id' => 'products', 'form_id' => '1'),
                    array( 'id' => 'manufacturers', 'form_id' => '1')
                );

and use a loop like this to create some stuff:

foreach ($tabs as $tab) {
                echo '<div role="tabpanel" class="tab-pane active" id="' . $key['id'] .'">';
                the_widget('MRP_Rating_Results_List_Widget', 'result_type=percentage&rating_form_id=' . $key['form_id']);
                echo '</div>';
              }

But it's not working, what am I doing wrong here?

2 Answers

Hi Boris,

By just reading your coding, and not testing it, I noticed in your foreach that you're using $key instead of the available variable $tab. Perhaps making that change will fix the issue? If not, I'll take a deeper look at it.

J.R. Champ
J.R. Champ
13,263 Points

You are right Robert, it worked for me.

foreach ($tabs as $key) {

    echo $key["id"] . "<br/>";
    echo $key["form_id"] . "<br/>";

};