diff --git a/reference/array/functions/range.xml b/reference/array/functions/range.xml index 6f2c32b89180..3db687315730 100644 --- a/reference/array/functions/range.xml +++ b/reference/array/functions/range.xml @@ -1,5 +1,4 @@ - range @@ -16,7 +15,19 @@ Create an array containing a range of elements. + + If both start and end are + strings, and step is int + the produced array will be a sequence of bytes. + Otherwise, the produced array will be a sequence of numbers. + + + The sequence is increasing if start is less than + equal to end. + Otherwise, the sequence is decreasing. + + &reftitle.parameters; @@ -33,8 +44,7 @@ end - The sequence is ended upon reaching the - end value. + Last possible value of the sequence. @@ -42,23 +52,190 @@ step - If a step value is given, it will be used as the - increment (or decrement) between elements in the sequence. step - must not equal 0 and must not exceed the specified range. If not specified, - step will default to 1. + step indicates by how much is the produced + sequence progressed between values of the sequence. + + + step may be negative for decreasing sequences. + + + If step is a float without a + fractional part, it is interpreted as int. + &reftitle.returnvalues; - Returns an array of elements from start to - end, inclusive. + Returns a sequence of elements as an array with the first + element being start going up to + end, with each value of the sequence being + step values apart. + + + The last element of the returned array is either end + or the previous element of the sequence, + depending on the value of step. + + + If both start and end are + strings, and step is int + the produced array will be a sequence of bytes, + generally latin ASCII characters. + + + If at least one of start, end, + or step is float + the produced array will be a sequence of float. + + + Otherwise, the produced array will be a sequence of int. + + + &reftitle.errors; + + + + If step is 0, + a ValueError is thrown. + + + + + If start, end, + or step is not is_finite, + a ValueError is thrown. + + + + + If step is negative, + but the produced range is increasing + (i.e. $start <= $end), + a ValueError is thrown. + + + + + If start or end + is the empty string '', + an E_WARNING is emitted and + the empty string will be interpreted as 0. + + + + + If start or end + non-numeric string + with more than one byte, an E_WARNING is emitted. + + + + + If start or end is a string + that is implicitly cast to an int because the other boundary + value is a number, an E_WARNING is emitted. + + + + + If step is a float, + and start and end are + non-numeric string, + an E_WARNING is emitted. + + + + + + + &reftitle.changelog; + + + + + &Version; + &Description; + + + + + 8.3.0 + + If both start and end + are strings then range will now always produce + an array of bytes. + Previously if one of the boundary values was a numeric string, + then the other boundary value was implicitly cast to int. + + + + 8.3.0 + + An E_WARNING is now emitted if + start or end + is a string that is implicitly cast to int + because the other boundary value is a number. + + + + 8.3.0 + + An E_WARNING is now emitted if + start or end + is a non-numeric string with more than one byte. + + + + 8.3.0 + + An E_WARNING is now emitted if + start or end + is the empty string. + + + + 8.3.0 + + If step is a float with no + fractional part, it will be interpreted as an int. + + + + 8.3.0 + + A ValueError is now thrown if + step is negative when producing an increasing + range. + + + + 8.3.0 + + A ValueError is now thrown if + step is not finite. + + + + 8.3.0 + + A TypeError is now thrown if + start or end + is an array, object, or resource. + Previously they were implicitly cast to int. + + + + + + + &reftitle.examples; @@ -67,48 +244,32 @@ ]]> + &example.outputs; + + + - - &reftitle.notes; - - - Character sequence values are limited to a length of one. If a length greater - than one is entered, only the first character is used. - - - + &reftitle.seealso; @@ -119,6 +280,7 @@ foreach (range('c', 'a') as $letter) { +