{sequence:type:min:max:step:delimiter}

Description

Builds a sequence of values and returns them as a JSON array (the default) or joined by a delimiter you choose. Three sequence types: num (whole numbers from min to max), string (PHP character ranges such as A to E), and day (one timestamp per day across a date span). The result is meant to feed list commands - most often {options:...} to fill a year or letter dropdown, or {foreach:...} to loop. For num, both min and max must be plain non-negative whole numbers (a minus sign, decimal point, or letters yield an empty result); step defaults to 1, and the direction is chosen automatically (if min is greater than max the sequence counts down). An empty or unrecognised type, or a range that produces no values, returns an empty string.

Parameters

type required default (none - must be set)

Which kind of sequence to build. One of num, string, or day. An empty or unknown value produces an empty result.

min required default (none - must be set)

Start of the range. For num a non-negative whole number; for string the first character (PHP range, e.g. A); for day a date as a Unix timestamp or a strtotime string such as 2022-06-30 or today.

max required default (none - must be set)

End of the range (inclusive). Same formats as min. If max is below min the sequence counts down automatically.

step optional default 1

For num only: the gap between values. Taken as its absolute whole-number value; 0, empty, or non-numeric all mean 1. Ignored by string and day (which always move one unit per item).

delimiter optional default json

How to join the values. Omit it (or leave empty) to get a JSON array. Any other text - a comma, a dash, a space - is used as the separator in a plain joined string.

Examples

virtual{options:{sequence:num:2024:2020}:Year}
Expected(
Actual
The real-world use: feed a descending year range to {options:...} to render a select of years (newest first). Output is HTML, so this is illustrative rather than asserted.
virtual{sequence:day:2022-06-29:2022-07-01:: }
Expected(three Unix timestamps, one per day: 29 Jun, 30 Jun, 1 Jul 2022)
Actual[1656453600,1656540000,1656626400]
type day yields one Unix timestamp per day across the span. Dates may be strtotime strings (2022-06-30, today) or numeric timestamps. Wrap each with {date:...} to format. Exact timestamps depend on the server timezone, so this is illustrative.
test{sequence:num:1:5}
Expected[1,2,3,4,5]
Actual[1,2,3,4,5]
With no delimiter the values come back as a JSON array - the form {options:...} and {foreach::json} expect.
test{sequence:num:1:5::-}
Expected1-2-3-4-5
Actual1-2-3-4-5
Give a delimiter (here a dash) to get a plain joined string instead of JSON. The step is left empty, so it defaults to 1.
test{sequence:num:1:10:3:,}
Expected1,4,7,10
Actual1,4,7,10
step 3 takes every third value. The last value (10) is included because it lands exactly on a step.
test{sequence:num:5:1::-}
Expected5-4-3-2-1
Actual5-4-3-2-1
When max is below min the sequence counts down automatically - no negative step needed.
test{sequence:string:A:E}
Expected["A","B","C","D","E"]
Actual["A","B","C","D","E"]
type string builds a character range. A to E gives the five letters as a JSON array.
test{sequence:string:A:E::|}
ExpectedA|B|C|D|E
ActualA|B|C|D|E
The same letter range joined with a pipe. step is ignored for string sequences.
test{sequence:num:1:4:0:-}
Expected1-2-3-4
Actual1-2-3-4
A step of 0 (or empty, or non-numeric) is treated as 1, so no values are skipped.
test[{sequence:num:-2:3}]
Expected[]
Actual[]
num only accepts non-negative whole numbers. A minus sign (or a decimal point or letters) fails the digit check and the whole expression returns an empty string.
test{foreach:{sequence:num:1:3:1:-}:[_#1]}
Expected[1][2][3]
Actual[1][2][3]
Feed the sequence to {foreach:...} to build markup per value. Match the sequence delimiter (-) to foreach's value delimiter. Here each value is wrapped in brackets.