Creating an array without keys in a loop

后端 未结 4 438
小鲜肉
小鲜肉 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:26

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

    array_combine($array1,$array1) 
    
    0 讨论(0)
  • 2020-12-17 10:27

    You could try Array_column(the name of the array, then the positions you want to get). Then print_r (result)

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-17 10:38

    you can't have an array without keys.

    Array(19,18,21)
    

    this array has keys 0,1 and 2.

    0 讨论(0)
提交回复
热议问题