0

I have an array of this form :

Array
(
    [1] => A
    [2] => B
    [3] => C
)

I want to delete values where key = 1 and 2... I have tried this

unset($array['1']);
unset($array['2']);

But I need to call 2 times unset... It's possible without 2 calls ?

Thanks, have a good day!

Payal Sorathiya
  • 756
  • 1
  • 8
  • 23
Orion
  • 158
  • 1
  • 7

1 Answers1

-1

You can try like

$keyToRemove = array('1', '2');

foreach($keyToRemove as $key) {
   unset($arr[$key]);
}

Also you can do it like this way too

$arr = array_diff_key($arr, array_flip($keyToRemove));

Similar answer you can check it here

Nipun Tyagi
  • 878
  • 9
  • 26
  • *But I need to call 2 times unset... It's possible without 2 calls ?* this is still 2 calls of unset. – Andreas May 17 '18 at 08:00