2

Lets say I end up with an array like such:

Array ( [0] => Array ( [0] => user 
                       [1] => pass
                     ) 
)

maybe as a result of passing an array through a function and using func_get_args()

In this case, I would want to get rid of the initial array, so I just end up with:

Array ( [0] => user 
        [1] => pass
) 

I know I could make a function to accomplish this, and push each element into a new array, however, is there some built in functionality with PHP that can pull this off?

4 Answers 4

5
$new_array = $old_array[0];

...

5

array_pop() will pop the last (first, if only 1 is present) element.

2
  • why would you use a function to access a directly accessible member of the single element array? Jul 11, 2011 at 21:57
  • 1
    Scared of hardcoding indexes :D Jul 11, 2011 at 22:00
1

Just take the value of the first element of the "outer" array.

0

I would recommend array_shift as it removes and returns the first element off of the beginning of the array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.