Removing Array Elements4:50 with Alena Holligan
Let's hope our todo list is getting smaller because we're getting stuff done, so we need to be able to remove things from our list. In this video we'll look at three ways php gives us to remove an element from an array.
array_shift: Shift an element off the beginning of array.
array_pop: Pop the element off the end of array
unset: Unset a given variable (works on more than array values)
Keep in Mind
unset($array); will remove your entire array.
Everytime you call array_shift you remove an element:
$removed = array_shift($learn); echo 'you removed ' . array_shift($learn);
Would remove two elements from the array.
Additional Option for Modifying an Array
Array Splice: remove a portion of the array and replace it with something else
You need to sign up for Treehouse in order to download course files.Sign up