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];

...

Sign up to request clarification or add additional context in comments.

Comments

5

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

2 Comments

why would you use a function to access a directly accessible member of the single element array?
Scared of hardcoding indexes :D
1

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

Comments

0

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.