range— 建立一个包含指定范围单元的数组 (數字、字母)

时间:2023-12-16 13:07:44

range()函数快速创建从1到12的数字数组

$numbers=range(0,12);
echo '<pre>';
print_r($numbers);
echo '</pre>';
//輸出
/*
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
[6] => 6
[7] => 7
[8] => 8
[9] => 9
[10] => 10
[11] => 11
[12] => 12
) */

php函数range()还可以创建从a到z的或A到Z的字符数组,用法同上

range()函数快速创建从a到g的字母数组

$numbers=range('a','g');
echo '<pre>';
print_r($numbers);
echo '</pre>';
//輸出
/*
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => g
)
*/