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

Kiran Woochit
Kiran Woochit
2,135 Points

PHP Basics - Data Types - Stuck on code challenge, Challenge 7

I seem to be having trouble with the final task for the code challenge for PHP Basics - Data Types.

It would seem the syntax error would indicate that the interpreter is looking for a quotation mark prematurely (on the line 16 for 'jane', although there is still one remaining key after)

Any help will be much appreciated.

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 $colors[1];

$favorite_colors = array
  (
    'mike' => 'green'
    'jane' => 'blue'
    'chris' => 'yellow')
?>
Kiran Woochit
Kiran Woochit
2,135 Points

I have also seen that when you click the above link to take you to the code challenge you end up on the wrong course. You will find the task under PHP Basics - Data Types. Thanks again.

Abhishek Bhardwaj
Abhishek Bhardwaj
3,316 Points

<?php $favorite_colors = array ( 'mike' => 'green', 'jane' => 'blue', 'chris' => 'yellow');

?> Note : Semi -colon should be at last of the statement and (,) comma to seprate the array elements

2 Answers

Pepe Suarez
Pepe Suarez
18,267 Points

Hey Kiran! You are just missing the commas to separate each item (key and value) on the last associative array. This is the code I used to complete the challenge:

<?php

//Place your code below this comment
$integer_one = 1;
$integer_two = 2;
$golden = 1.618;

$bool = true;

$colors = array("red","blue","green");

echo $colors[1];

$favorite_colors = array(

  'mike' => "green",
  'jane' => "blue",
  'chris' => "yellow"

);

?>

Hope this helps!!

Kiran Woochit
Kiran Woochit
2,135 Points

Thanks for all your help guys, the commas (or lack of should I say) were indeed the problem! After adding them the code seemed to work fine!