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 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.