Creating an array without keys in a loop

The closest you are going to get is to combine so your keys are your values

array_combine($array1,$array1) 

you can't have an array without keys.

Array(19,18,21)

this array has keys 0,1 and 2.


Arrays (in PHP) always have (at least) numeric indices. However, you can extract the values via array_values(). This returns only the values of the given array. It of course has indices, but they are continous and they are numeric. Thats the most simple array representation you can have in PHP.

Update, just to make that clear: You cannot have an array without indices in PHP (as far as I know in any other language thats quite the same), because internaly arrays are always hashmaps and hashmaps always needs a key. The "most common key" are indices. You cannot omit the "keys". On the other side I dont the any reason why one should want it. If you dont want to use the keys, just dont use the keys and thats really all. PHP is quite gentle in this point.

Tags:

Php

Arrays