Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP remove array keys

Tags:

arrays

php

key

I have

Array ( [0] => 2088 [1] => 2087 [2] => 2091 [3] => 2083 [4] => 2086 [5] => 2085 [6] => 2084 [7] => 2092 [8] => 2089 [10] => 2122 [11] => 2122 )

As you can see i don't have array key number 9

How can i move other keys down so [9] => 2122 [10] => 2122 ?

Thanks

like image 887
Bluestar Avatar asked Jan 08 '23 21:01

Bluestar


1 Answers

You can use array_values to accomplish this

$array = array ( 0 => 2088, 1 => 2087, 2 => 2091, 3 => 2083, 4 => 2086, 5 => 2085, 6 => 2084, 7 => 2092, 8 => 2089, 10 => 2122, 11 => 2122 );
$newarray = array_values($array);
var_dump($newarray);

http://codepad.org/rQkKOp0k

like image 187
Musa Avatar answered Jan 15 '23 00:01

Musa