range() 函數(shù)根據(jù)范圍創(chuàng)建數(shù)組,包含指定的元素
range ( $low, $high [, $step] );
此函數(shù)返回從low到high(包括low和high值)的元素?cái)?shù)組。如果low > high,順序?qū)母叩降汀?/p>
序號 | 參數(shù)及說明 |
---|---|
1 | low(必需) 這是數(shù)組的下限 |
2 | high(必需) 這是數(shù)組的上限 |
3 | step(可選) 增加數(shù)組元素的步驟。默認(rèn)為1 |
它返回元素?cái)?shù)組,返回的數(shù)組中從 low 到 high (含 low 和 high)的元素。
<?php foreach (range(0, 6) as $number) { echo "$number, "; } print "\n"; foreach (range(0, 100, 10) as $number) { echo "$number, "; } print "\n"; foreach (range('a', 'c') as $letter) { echo "$letter, "; } print "\n"; foreach (range('f', 'a') as $letter) { echo "$letter, "; } print "\n"; ?>測試看看?/?
輸出結(jié)果:
0, 1, 2, 3, 4, 5, 6, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 a, b, c, f,e,d,c, b, a