Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Basics (Retired) PHP Datatypes PHP Datatypes Challenge

Creating an Associaed arrays in PHP.

how do you add an associative array named $favorite_colors. The keys will be, in order, the following: 'mike', 'jane', & 'chris' with values for each. Those values are 'green', 'blue', & 'yellow'?

index.php
<?php

//Place your code below this comment
$integer_one = 1;
$integer_two = 2;
$golden = 1.618;
$bool = true;
$colors = array ("red","blue","green");
echo ("blue");



?>

3 Answers

Hey, firstly I think you mean associative array and the example I've attched might be what you're looking for :)

$favorite_colors = array("Mike"=>"green", "Jane"=>"blue", "Chris"=>"yellow");

My advice would be to look through here (http://www.w3schools.com/php/func_array.asp). This might come in handy.

Have a great weekend

$favorite_colors = array("Mike" =>"green", "Jane"=>"blue", "Chris"=>"yellow");

Jaime Rios
PLUS
Jaime Rios
Courses Plus Student 21,100 Points

Sorry for taking so long to answer. Since rhysadams is a good example, normally you want to declare your variable as an empty array. Here is an example of what I mean:

$galeria = [];
$galeria[101] = [
    "titulo" => "Objeto 1",
    "img" => "http://lorempixel.com/400/200/",
    "ubicacion" => "hermosillo, sonora",
    "tipo de sistema" => "mixto-biologico",
    "año" => "2012"
    ];

As a side note, something really helped me internalize the concepts is to develop a website like that with custom content.