Filling an array with numbers sequentially

后端 未结 2 540
执念已碎
执念已碎 2021-01-17 10:03

I have a number (e.g. 6) that is dynamically generated and I would like to fill an array with the numbers 1 through the dynamically generated number (in this example, 6):

相关标签:
2条回答
  • 2021-01-17 10:33

    Use range:

    $arr = range(1,6);
    // Returns an array of elements from start to limit, inclusive.
    
    0 讨论(0)
  • 2021-01-17 10:40

    This is what you are looking for:

    range(1, 6)
    
    0 讨论(0)
提交回复
热议问题