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

Echo out an Array within another Array?

I am trying to echo an array within another array...here is the code

$products = array();
$products[101] = array(
"a" => "Blue & White Stripes",
"b" => 35,
"c" => "img/shirts.jpg",
"d" => "Red",
"e" => array("Small", "Medium", "Large", "X-Large"),
"f" => "img.jpg",
"g" => "Orange"
);

I am trying to echo out the array within $product["e"].

Does anyone know how to do this?

3 Answers

Sorry the array messed up

$products = array();
$products[101] = array(
"a" => "Blue & White Stripes",
"b" => 35,
"c" => "img/shirt.jpg",
"d" => "Red",
"e" => array("Small", "Medium", "Large", "X-Large"),
"f" => "img.jpg",
"d" => "Orange"
);  
Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Something like this?

<?php

    foreach($product["e"] as $size) {
        echo $size;
    }

?>

That worked! Thanks for the help Randy.