P
P
profseo20122016-09-13 09:34:29
PHP
profseo2012, 2016-09-13 09:34:29

Removing array elements. How to remove multiple keys?

The situation is this.
have an array

$options = array( 
    
    '749' => Array
       (
         'id' => 1,
         'good' => 749,
         'name' => 'test'
       ),
    
    '800' => Array
       (
         'id' => 3,
         'good' => 875,
         'name' => 'test9'
       ),
    
    '1090' => Array
       (
         'id' => 2,
         'good' => 4222,
         'name' => 'test6'
       )
  );

Through the form we get for example two IDs - these are 1090 and 800 how to delete these two arrays?
Number of IDs unknown

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Muhammad, 2016-09-13
@muhammad_97

Cycle:

foreach ($ids as $id) {
    unset($options[$id]);
}

M
Maxim Fedorov, 2016-09-13
@qonand

not quite clear Do you need to delete by ID or by keys?
judging by this, you still mean the keys of the $options array, if so then you can simply use:
unset($options[749],$options[1090]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question