range
range
Create an array containing a range of elements
array **range** $start $end $step
Create an array containing a range of elements.
If both and are
s, and is
the produced array will be a sequence of bytes.
Otherwise, the produced array will be a sequence of numbers.
start``end``string``step``int
The sequence is increasing if is less than
equal to .
Otherwise, the sequence is decreasing.
start``end
startFirst value of the sequence.
endLast possible value of the sequence.
step
indicates by how much is the produced
sequence progressed between values of the sequence.
step
may be negative for decreasing sequences.
`step`
If is a without a
fractional part, it is interpreted as .
`step``float``int`
Returns a sequence of elements as an with the first
element being going up to
, with each value of the sequence being
values apart.
array``start``end``step
The last element of the returned array is either
or the previous element of the sequence,
depending on the value of .
end``step
If both and are
s, and is
the produced array will be a sequence of bytes,
generally latin characters.
start``end``string``step``int
If at least one of , ,
or is
the produced array will be a sequence of .
start``end``step``float``float
Otherwise, the produced array will be a sequence of .
int
-
If is , a is thrown.
step``0``ValueError -
If , , or is not , a is thrown.
start``end``step``is_finite``ValueError -
If is negative, but the produced range is increasing (i.e. ), a is thrown.
step``$start <= $end``ValueError -
If or is the empty string , an is emitted and the empty string will be interpreted as .
start``end``''``E_WARNING``0 -
If or is a non- with more than one byte, an is emitted.
start``endnumeric stringE_WARNING -
If or is a string that is implicitly cast to an because the other boundary value is a number, an is emitted.
start``end``int``E_WARNING -
If is a , and and are non-, an is emitted.
step``float``start``endnumeric stringE_WARNINGVoorbeeld: examples
<?php
echo implode(', ', range(0, 12)), PHP_EOL;
echo implode(', ', range(0, 100, 10)), PHP_EOL;
echo implode(', ', range('a', 'i')), PHP_EOL;
echo implode(', ', range('c', 'a')), PHP_EOL;
echo implode(', ', range('A', 'z')), PHP_EOL;
?>
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
a, b, c, d, e, f, g, h, i
c, b, a
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, [, \, ], ^, _, `, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
shuffle``array_fill