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!

0

1 Answer 1

-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

Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.