Destroy a single element of an array
unset()
$array1 = array('A', 'B', 'C', 'D', 'E');
unset($array1[2]); // deleteDelete known index(2) value from array
var_dump($array1);
Out putThe output will be:
array(4) {
[0]=>
string(1) "A"
[1]=>
string(1) "B"
[3]=>
string(1) "D"
[4]=>
string(1) "E"
}
If you need to re indexingindex the array:
$array1=array_values$array1 = array_values($array1);
var_dump($array1);
Then Outputthe output will be:
array(4) {
[0]=>
string(1) "A"
[1]=>
string(1) "B"
[2]=>
string(1) "D"
[3]=>
string(1) "E"
}
Pop the element off the end of array - return the value of the removed element
mixed array_pop ( array &$array )
$stack = array("orange", "banana", "apple", "raspberry");
$last_fruit = array_pop($stack);
print_r($stack);
print_r('Last Fruit :'.$last_fruit); // Last element of the array
OutputThe output will be
Array
(
[0] => orange
[1] => banana
[2] => apple
)
Last Fruit : raspberry
Remove the first element (red) from an array, - return the value of the removed element
mixed array_shift ( array &$array )
$color=array$color = array("a"=>"red""a" => "red","b"=>"green" "b" => "green" ,"c"=>"blue" "c" => "blue");
$first_color=array_shift$first_color = array_shift($color);
print_r ($color);
print_r ('First Color : '.$first_color);
OutputThe output will be:
Array
(
[b] => green
[c] => blue
)
First Color : red