-2

I unset all the even index values from my array using this:

foreach($arr as $key => $value) if(!($key&1)) unset($arr [$key]);

and when I print the array structure using print_r() I get:

Array ( [1] => name1 [3] => name2 ) 

How to reindexing after filtering my array so the structure would be:

Array ( [0] => name1 [1] => name2 ) 

1 Answers1

1

Use array_values()

$arr = array_values($arr);
John Conde
  • 217,595
  • 99
  • 455
  • 496