Removing elements from an array using PHP

I have two arrays

$alpha=array('a','b','c','d','e','f');

$index=array('2','5');

I need to remove elements in the first array with index from the second array.

(Delete c-index is 2 and index f is 5)

So the returned array

{'a', 'b', 'd', 'e'}

How can I do this using PHP? Thanks

Edit

Actually I need a finite array as follows

[0]=>a
[1]=>b
[2]=>d
[3]=>e

Reset returns an array with the same index

0 => string 'a' 
2 => string 'c' 
3 => string 'd' 
4 => string 'e' 
+5
source share
5 answers
foreach ($index as $key) {
    unset($alpha[$key]);
}

had it like array_unset () before.

+3
source

Please try this for better performance:

var_dump(array_diff_key($alpha, array_flip($index)));
+3
source

( , $alpha $index , php):

function remove_keys($array, $indexes = array()){
  return array_intersect_key($array, array_diff(array_keys($array),$indexes));
}

IDEOne

+2

$index , unset():

<?php
$alpha=array('a','b','c','d','e','f');  
$index=array('2','5'); 

foreach ($index as $key) {     
    unset($alpha[$key]);
} 

var_dump($alpha);
?>

:

array(4) { [0]=> string(1) "a" [1]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "e" } 
+1

:

$array = array('a', 'b','c');
unset($array[0]);
$array = array_values($array); //reindexing
0