0

I have a numeric index array.

It can begin with any number, and then go on a hundred times.

I would rather have it ordered.

Example:

$myarray = array();

$myarray[500] = 2;
$myarray[501] = 3;

Should be:

$myarray[0] = 2;
$myarray[1] = 3;

I know I could do this with a foreach:

$i = 0;

foreach($myarray as $key => $value){
$myarray[$i] = $value;
$i++
}

Is there any function for this in PHP?

3
  • 2
    $myarray = array_values($myarray); Commented Jun 6, 2017 at 12:40
  • @CasimiretHippolyte Perfect. You might want to add it as an answer. Commented Jun 6, 2017 at 12:42
  • Possible Duplicate stackoverflow.com/questions/10492839/… Commented Jun 6, 2017 at 12:45

1 Answer 1

1

try with array_value

$myArray  = array_values($myArray);

Array_value will reset the key numerically and returns all the values from the 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.