Alternative to array_shift function

Posted by SoLoGHoST on Stack Overflow See other posts from Stack Overflow or by SoLoGHoST
Published on 2010-04-29T06:34:33Z Indexed on 2010/04/29 6:47 UTC
Read the original article Hit count: 447

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays