Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:59:06+00:00 2026-05-27T19:59:06+00:00

I have some arrays that I’d like to unset based on a key. For

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:59:07+00:00Added an answer on May 27, 2026 at 7:59 pm

    You can use this function:

    function delete(&$array, $keys)
    {
       $key = array_shift($keys);
    
       if (count($keys) == 0)
          unset($array[$key]);
       else
          delete($array[$key], $keys);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data that goes over three levels, like this: Identifier, Key, Value
I have some Javascript code that creates 2 arrays: One for Product Category and
I have an array ($configOptions) which contains some arrays. Each array ($option) in that
I have three arrays that need to be combined in one three-dimension array. The
I have some dynamic int * arrays that I would like to use as
I have a function that returns json (networks_function.php builds up some arrays and encodes
I have a mutable array that is retained and storing several objects. At some
I have an array set inside a velocity template that contains some paths. The
I have applications(WinForm) that gets some objects from webservice. After receiving array I transform
I ran some CUDA code that updated an array of floats. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.