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 PHP Arrays and Control Structures PHP Arrays Associative Quiz

Alex Forseth
Alex Forseth
8,017 Points

What is the key and what is the value in php?

What is the key and what is the value in php?

1 Answer

jamesjones21
jamesjones21
9,260 Points

Hi Alex,

Best way to describe a key and value is in an associative array. Like in Aleanas class, where she described an ice cream list.

$iceCream = array (

‘James’ => ‘I like strawberry icecream’, ‘Jim’ => ‘I like raspberry icecream’, );

Where the names are is the key, which if we want to use the key to be called into a table then we can just define $iceCream[‘James’], this will then bring back my name and my favourite iceCream as the value. You can see this if we use a var_dump($iceCream); you will be able to see the key and value.

A key I would class as the identifier, and value is the content of the key.

Arrays always start from 0 as the first key and then increments the second element as 1, then 2 and so forth.

Hope this has provided you with an example and an idea.

Kind regards, James Sorry for any typos, on my phone typing this.