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 Removing Array Elements

I'm Not Understanding what Unset is/does Fully.

I just watched Alena's video where she intro's Unset, but I'm not understanding fully what the point of unset is. It removes items from an array, but is the removal permanent? Is this the closest we get in PHP to a delete function in an array vs. array_shift/pop?

5 Answers

Amy Dollar
Amy Dollar
2,562 Points

Yes he probably did Alexander, but these questions are also useful for others who are new to the lessons ;)

i am also working with php Alex . I would suggest that if you don't get any concept watch the video as much as possible. After you got it don't stop go to workspaces or whichever code editor and try using that concept. Application of concepts is most important in web dev. Hope this helps! Bye bye -saif ahmad

I think she was saying that you can use unset to take it out of an array and if you need to put it somewhere else. All unset does is it takes the value AND its key out of the current array to be placed somewhere else.

Um... You are replying to a question made 1 month ago lol :laughing:

I think Nekilof already found out the answer to her question.

Sam Gord
Sam Gord
14,084 Points

unless gives you the ability to remove elements from an array by their index number, its pretty easy .

$learn = array('html','css','javascript'); html's index number ( key ) --> 0 css's index number ( key ) --> 1 javascript's index number ( key ) --> 2

unset($learn[1],$learn[2]);

here i removed 'css' and 'javascript' from $learn array using unset .

You should try experimenting that in Workspaces :)

If you want to create a Workspace you can create (up to 100!) Workspaces here.

Coding is very important, maybe even (slightly) more important than watching the videos!

Also researching can help a ton. You can always search up your question on Google or any other search engine you enjoy using :smile:

I hope this helps. ~Alex