PHP – Remove an item from an array

In this post we will be creating a PHP script that will remove an item from an array, arrays in PHP enable us to store multiple values in to one single variable. To remove an item we will be using the ‘unset()’ function which will destroy the specified variable.

See below our PHP array for this example filled with a list of names.

$array = array("James", "Harry", "Kira", "Rahul", "Leo");

To remove James from the array above we would use the snippet of code below. Here we are referencing the item by its index, the index of James within our array is 0.

	$array = array("James", "Harry", "Kira", "Rahul", "Leo");


Leave a Reply