php函数range()是用于生成一系列连续的数字或字母的函数
▥php
𝄐 0
phprange函数,phprange函数怎么用,phprange
php函数range()是用于生成一系列连续的数字或字母的函数。
range()函数具有以下语法:
php
range($start, $end, $step);
其中,$start表示序列的起始值,$end表示序列的结束值,$step表示序列中相邻两个值之间的步长(默认为1)。
下面是一些示例:
php
// 生成1到10的整数序列
$numbers = range(1, 10);
print_r($numbers);
// 生成从a到z的字母序列
$letters = range('a', 'z');
print_r($letters);
// 生成1到100之间的偶数序列
$even_numbers = range(2, 100, 2);
print_r($even_numbers);
以上代码执行后的输出结果分别为:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
)
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => g
[7] => h
[8] => i
[9] => j
[10] => k
[11] => l
[12] => m
[13] => n
[14] => o
[15] => p
[16] => q
[17] => r
[18] => s
[19] => t
[20] => u
[21] => v
[22] => w
[23] => x
[24] => y
[25] => z
)
Array
(
[0] => 2
[1] => 4
[2] => 6
[3] => 8
[4] => 10
[5] => 12
[6] => 14
[7] => 16
[8] => 18
[9] => 20
[10] => 22
[11] => 24
[12] => 26
[13] => 28
[14] => 30
[15] => 32
[16] => 34
[17] => 36
[18] => 38
[19] => 40
[20] => 42
[21] => 44
[22] => 46
[23] => 48
[24] => 50
[25] => 52
[26] => 54
[27] => 56
[28] => 58
[29] => 60
[30] => 62
[31] => 64
[32] => 66
[33] => 68
[34] => 70
[35] => 72
[36] => 74
[37] => 76
[38] => 78
[39] => 80
[40] => 82
[41] => 84
[42] => 86
[43] => 88
[44] => 90
[45] => 92
[46] => 94
[47] => 96
[48] => 98
[49] => 100
)
php函数range()是用于生成一系列连续的数字或字母的函数。
range()函数具有以下语法:
php
range($start, $end, $step);
其中,$start表示序列的起始值,$end表示序列的结束值,$step表示序列中相邻两个值之间的步长(默认为1)。
下面是一些示例:
php
// 生成1到10的整数序列
$numbers = range(1, 10);
print_r($numbers);
// 生成从a到z的字母序列
$letters = range('a', 'z');
print_r($letters);
// 生成1到100之间的偶数序列
$even_numbers = range(2, 100, 2);
print_r($even_numbers);
以上代码执行后的输出结果分别为:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
)
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => g
[7] => h
[8] => i
[9] => j
[10] => k
[11] => l
[12] => m
[13] => n
[14] => o
[15] => p
[16] => q
[17] => r
[18] => s
[19] => t
[20] => u
[21] => v
[22] => w
[23] => x
[24] => y
[25] => z
)
Array
(
[0] => 2
[1] => 4
[2] => 6
[3] => 8
[4] => 10
[5] => 12
[6] => 14
[7] => 16
[8] => 18
[9] => 20
[10] => 22
[11] => 24
[12] => 26
[13] => 28
[14] => 30
[15] => 32
[16] => 34
[17] => 36
[18] => 38
[19] => 40
[20] => 42
[21] => 44
[22] => 46
[23] => 48
[24] => 50
[25] => 52
[26] => 54
[27] => 56
[28] => 58
[29] => 60
[30] => 62
[31] => 64
[32] => 66
[33] => 68
[34] => 70
[35] => 72
[36] => 74
[37] => 76
[38] => 78
[39] => 80
[40] => 82
[41] => 84
[42] => 86
[43] => 88
[44] => 90
[45] => 92
[46] => 94
[47] => 96
[48] => 98
[49] => 100
)
本文地址:
/show-271382.html
版权声明:除非特别标注原创,其它均来自互联网,转载时请以链接形式注明文章出处。