0

Var_dump() of my array before array_filter():

array(2) { [0]=> string(0) "" [1]=> string(2) "46" }

Var_dump() of my array after array_filter():

array(1) { [1]=> string(2) "46" }

However I want to get array(1) { [0]=> string(2) "46" }, with the remaining element at the beginning of the array (0, not 1). How to do that?

1
  • 1
    messes up their location? No, actually it leaves the keys exactly as they were.... if you want to change that, then wrap your array_filter() call in an array_values() call Commented Jan 19, 2015 at 11:49

1 Answer 1

4

Use array_values to reindex an array.

$filtered_array = array_values(array_filter($array));
Sign up to request clarification or add additional context in comments.

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.