依次用数字填充数组

编程入门 行业动态 更新时间:2024-10-23 12:34:00
本文介绍了依次用数字填充数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个动态生成的数字(例如6),我想通过动态生成的数字(在本例中为6)用数字1填充数组:

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):

array(1, 2, 3, 4, 5, 6);

我目前唯一知道的方法是使用for循环,但是我想知道是否还有更好的方法,类似于array_fill.我看了一下array_fill,但看起来并不需要一个数字并将其递增设定的次数.

The only way I know to do this at the moment is by using a for loop, but I'm wondering if there's a better way, something similar to array_fill. I looked at array_fill, but it doesn't look like it will take a number and increment it for a set number of times.

推荐答案

使用范围:

$arr = range(1,6); // Returns an array of elements from start to limit, inclusive.

更多推荐

依次用数字填充数组

本文发布于:2023-08-05 21:24:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1308140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!