Is there an easy way to delete an element from an array using PHP, such that foreach ($array)
no longer includes that element?
I thought that setting it
Two ways for removing the first item of an array with keeping order of the index and also if you don't know the key name of the first item.
// 1 is the index of the first object to get
// NULL to get everything until the end
// true to preserve keys
$array = array_slice($array, 1, null, true);
// Rewinds the array's internal pointer to the first element
// and returns the value of the first array element.
$value = reset($array);
// Returns the index element of the current array position
$key = key($array);
unset($array[$key]);
For this sample data:
$array = array(10 => "a", 20 => "b", 30 => "c");
You must have this result:
array(2) {
[20]=>
string(1) "b"
[30]=>
string(1) "c"
}