Rebuild php array

I have an array

Array ( [1] => Vice President [3] => Secretary [5] => Treasurer ) 

I want to change it to

 Array ( [0] => Vice President [1] => Secretary [2] => Treasurer ) 

I tried php for loop function

 $ub_new_arr_sort = array(); for($i3 = 0; $i3 < count($ub_new_arr); $i3++){ $ub_new_arr_sort[] = $ub_new_arr[$i3]; } 

but it doesn't seem to work at all, any idea?

Thanks for the promotion.

+4
source share
2 answers

Just use array_values .

 $array = array_values($array); 
+12
source

Use foreach instead of being "key independent":

 foreach($oldarray as $position){ $newArray[] = $position; } print_r($newArray); 
+1
source

All Articles