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 Modifying Arrays

Adding element to beginning of array . . . what's wrong with array_unshift in this task?

Am doing the task in PHP Arrays and Control Structures where you have to add "Yellow" to the beginning and "Black" to the end of the array $colors. I'm doing the following:

$colors = array_unshift($colors, "Yellow");

It's telling me "Bummer! Add "Yellow" to the BEGINNING of the array"

Am I missing something?

index.php
<?php

$colors = array("Red","Green","Blue");

//add modifications below this line
$colors = array_unshift($colors, "Yellow");
$colors = array_push($colors, "Black");

1 Answer

Sean T. Unwin
Sean T. Unwin
28,690 Points

The Array functions take an array as a first parameter so we don't have to use $colors = before them. They are self-enclosed and modify the array within the function so they don't return an array.

tl;dr: Remove $colors = from the array_* function calls.