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

Try to figure out the corresponding method about the display of array.

I do remember that there is a video which taught us about how to display the associate information in an array instead of displaying repeat information.

Here is an array example which store name and price of the product:

$product = array ();

$products [0] = array( "Name" => "abc"; "Price" => 123; };

And the displaying message will be:

array [0] { Name: abc; [0] : abc; Price:123;

}

How can I modify my codes so that it just display:

array [0] { Name: abc; Price:123;}

3 Answers

Not sure I know what you are looking for as the message to print to the screen.

Hey there, chk this quick tut on PHP associative array https://www.youtube.com/watch?v=N_IhwFqIg6Y

Hi, I don't fully understand your question, but here's how I'd display data in an associative array : $product = array('Name' => 'Abc', 'Price' => '123'); //to output data echo $product [ name ]; echo $product [ price ]; or similarly in a for each loop : foreach ($product as $key => $value) {echo $key.' '.$value; }

Well actually I was trying to figure out the command (I guess that is sth about "isset" function) that can only display the relative information.

Like the example shirts 4 Mike, the product information was displayed like:

array[0] { name = "Logo Shirt, Red"; (This is the information we need) [0] = "Logo Shirt, Red"; (This is the repeat information, [0] means this is the first element which is store in the product array) price = 18; [1] = 18; (This is the repeat information, [1] means this is the second element which is store in the product array) .... }

If still feel confused, just press the "Markdown Cheatsheet" at the bottom so that you can see the original format when I typed.

unable to see your original format Sai