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 Build a Simple PHP Application Integrating with PayPal Redirecting Invalid Shirt IDs

Giovanni Valdenegro
Giovanni Valdenegro
13,871 Points

Calling Variables

So I need a little help understanding something here:

on Shirt. php I call <?php echo $product["img"]; ?> for example.

On the array it is under $products["img"], why does it work now on the singular form $product and not $products as it is declared on the array??

2 Answers

Ron McCranie
Ron McCranie
7,837 Points

$products is a multidimensional array (an array containing multiple arrays). On line 5 of shirt.php it grabs the product array from $products with the product_id specified and sets that array to a variable called $product. From that point forward $product is referencing one single product and then you can call it's properties like name, img, etc.

Giovanni Valdenegro
Giovanni Valdenegro
13,871 Points

Thank you for replying Ron. Its clear now

so $product = $products[$product_id], // Meaning that all the values under products[101] multidimensional array are now called from product.