0

I need to change my array index values from

 Array ( [0] => 84 [1] => 109 [4] => 78 )

to

  Array ( [1] => 84 [2] => 109 [3] => 78 )

Thank you.

0

2 Answers 2

0

Quick and dirty method

$arrayData = array_combine(
    range(1, count($arrayData)),
    $arrayData
);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you it works!!, but typo error.. you missed an bracket!!
0

If you want to re-index starting to zero, simply do the following:

$ArrayFromZero = array_values($arr);

If you need it to start at one, then use the following:

$arrayFromOne = array_combine(range(1, count($arr)), array_values($arr));

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.