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 766599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:04:24+00:00 2026-05-14T17:04:24+00:00

Ok, I need keys to be preserved within this array and I just want

  • 0

Ok, I need keys to be preserved within this array and I just want to shift the 1st element from this array. Actually I know that the first key of this array will always be 1 when I do this:

// Sort it by 1st group and 1st layout.
ksort($disabled_sections);
    foreach($disabled_sections as &$grouplayout)
        ksort($grouplayout);

Basically I’d rather not have to ksort it in order to grab this array where the key = 1. And, honestly, I’m not a big fan of array_shift, it just takes to long IMO. Is there another way. Perhaps a way to extract the entire array where $disabled_sections[1] is found without having to do a foreach and sorting it, and array_shift. I just wanna add $disabled[1] to a different array and remove it from this array altogether. While keeping both arrays keys structured the way they are. Technically, it would even be fine to do this:

$array = array();
$array = $disabled_sections[1];

But it needs to remove it from $disabled_sections. Can I use something like this approach…

$array = array();
$array = $disabled_sections[1];
$disabled_sections -= $disabled_sections[1];

Is something like the above even possible??

Thanks.

  • 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-14T17:04:24+00:00Added an answer on May 14, 2026 at 5:04 pm

    While there’s no -= operator in that fashion, you can use unset to remove that element from an array:

    unset(disabled_sections[1]);
    

    But that’s just implementing your own version of shift. I do wonder under what situation you’re finding array_shift() to be ‘slow’ and how you’re testing said slowness.

    Numeric arrays are sorted numerical by default – no ksort is required. Maybe you should try something like

    while($array = array_shift($group_of_arrays)) {
    
      // ... do stuff
    }
    

    If you are not concerned about the order in which you pull elements out of the array, you can use “array_pop” instead of “array_shift”. Since “array_pop” takes the elements off of the end of the array, no reindexing is required and performance increases dramatically. In testing with an array of about 80,000 entries I am seeing about a 90% decrease in processing time with “array_pop”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to keep the arrow keys from being able to scroll through my
I need a font that shows letters and function keys on a keyboard, so
I need a fast container with only two operations. Inserting keys on from a
I have potentially large files that need to be sorted by 1-n keys. Some
As stated in the title, I need double shortcut keys for my application (ie.
I need to disable specific keys (Ctrl and Backspace) in Internet Explorer 6. Is
I need custom behavior for tab keys in RichTextEdit control. Currenty the best I
In WPF need to trap the keys entered in a textblock to keep the
I have a HashMap relating Keys to Strings, and I need to compare some
Need a function that takes a character as a parameter and returns true if

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.