4

How to rearrange the array element from 0th index in the sequence to end in PHP?

UPDATED

I have an array:

$input =array{ 
                              2 => '13234390',
                              4 => '12345290',
                              5 => '21322210' 
                              }

now I want this array to be rearranged as

$input =array{ 
                              0 => '13234390',
                              1 => '12345290',
                              2 => '21322210' 
                              }

1 Answer 1

13

With

  • array_values() returns all the values from the input array and indexes numerically the array.

Example:

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

3 Comments

I s there any other way to do it... are u actually getting me.. I want rearrange the same array in proper sequence...
@OMThe well, yes. You could do usort($input, function() { return 1; }); which would not create a copy of the array, but that's about 3 to 4 times slower.
I used the array_values() but but arranged my values in ascending order.. i dont want the order of values to be changed

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.