I have some arrays that I'd like to unset based on a key.
For example, let's say I have this array:
$array = array(
'one' => array('item' => '1'),
'two' => array('item' => '2')
);
If I want to unset the nested array with key 'two', I could do:
unset($array['two'])
or if I wanted to unset just the item array for key 'two', I could do:
unset($array['two']['item'])
I want to dynamically delete array items based on known keys. So for example, I know I want to delete ['two']['item'].
How do I pass those two arguments to a method, that can then be appended to an array?
Example:
//This works fine if it's only the first item in the array
function deleteArray($keys)
{
unset($this->array[$keys]);
}
But when we want to delete nested items, this would not work. I could pass in the keys as an array such as array('two', 'item') and build the index off of this, but not sure how....
Any help would be great! thank you!