0

I have an array in php like:

$a = array(0=>'a', 1=>'b', 2=>'c', 3=>'d');

Now I unset an element in array:

unset($a[2]);

Now I have the array as:

$a = array(0=>'a', 1=>'b', 3=>'d');

But I want to reorder the array such that the indexes are numerically organized, like:

$a = array(0=>'a', 1=>'b', 2=>'d');

What I can do to get this change?

1

2 Answers 2

3

this should do it:

$new_array = array_values($old_array);
Sign up to request clarification or add additional context in comments.

Comments

1

A solution is to merge your array with an empty array, like so:

$a = array_merge(array(), $a);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.