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

add yellow and black to array

i tried two different ways. what am i missing?

index.php
<?php

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

//add modifications below this line
//array_push($learn,'Yellow');
//array_pop($learn,'Black');
$colors[0] = "Yellow" ;
$colors[4] = "Black" ;
Ryan LaFountain
Ryan LaFountain
5,449 Points

What is the objective? To move one to the front and one to the end?

To front use array_unshift($name, value);

To back use array_push($name, value);

Also note if commented out code is a previous attempt you have wrong variable name referenced.

thanks man! i had seen that i used the wrong syntax lol

1 Answer

Ryan LaFountain
Ryan LaFountain
5,449 Points

You are welcome! Syntax errors are killer. Pasting below as the answer.

What is the objective? To move one to the front and one to the end?

To front use array_unshift($name, value);

To back use array_push($name, value);

Also note if commented out code is a previous attempt you have wrong variable name referenced.