0

Possible Duplicate:
PHP remove the first index of an array and re-index
How to Remove Array Element and Then Re-Index Array?

$arr = array(1, 2, 3);

unset($arr[0]);

print_r($arr);

//Array ( [1] => 2 [2] => 3 ) 

What's the function called, so the output instead would be:

//Array ( [0] => 2 [1] => 3 ) 
Community
  • 1
  • 1
John
  • 2,900
  • 8
  • 36
  • 65
  • possible duplicate of [How to Remove Array Element and Then Re-Index Array?](http://stackoverflow.com/questions/5217721/how-to-remove-array-element-and-then-re-index-array) and [PHP remove the first index of an array and re-index](http://stackoverflow.com/questions/3003259/php-remove-the-first-index-of-an-array-and-re-index). – Felix Kling Jan 03 '13 at 21:15
  • Ah it was re-index I was looking for :P – John Jan 03 '13 at 21:33

1 Answers1

4

You want to create a new array using array_values:

$arr = array(1, 2, 3);
unset($arr[0]);
$arr = array_values($arr);

print_r($arr);
//Array ( [0] => 2 [1] => 3 ) 
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Adam Hopkinson
  • 28,281
  • 7
  • 65
  • 99