Take the following array:
$fruits = [
'apple', 'banana', 'grapefruit', 'orange', 'melon'
];
Grapefruits are just disgusting, so I would like to unset it.
$key = array_search('grapefruit', $fruit);
unset($fruit[$key]);
The grapefruit is out of my $fruit
array but my keys are no longer numbered correctly.
array(4) {
[0] => 'apple'
[1] => 'banana'
[3] => 'orange'
[4] => 'melon'
}
I Could loop through the array and create a new one but I was wondering if there's a simpler method to reset the keys.