Creating an array without keys in a loop

后端 未结 4 480
小鲜肉
小鲜肉 2020-12-17 10:04

This might be a brain fart, since it\'s a late day, but I\'m stuck here.

I need to take a $_POST value from a select box. (It\'s an array), and convert it to a simpl

4条回答
  •  被撕碎了的回忆
    2020-12-17 10:34

    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.

提交回复
热议问题