| Extracted from Pike v7.8 release 866 at 2018-07-18.

[Top]

# Method enumerate()

Method enumerate

  `array(int) enumerate(int n)`
  `array enumerate(int n, void|mixed step, void|mixed start, void|function operator)`

Description

  Create an array with an enumeration, useful for initializing arrays or as first argument to map() or foreach() .

  The defaults are: step = 1, start = 0, operator = `+

  ## Advanced use

  The resulting array is calculated like this:

  array enumerate(int n, mixed step, mixed start, function operator) { array res = allocate(n); for (int i=0; i < n; i++) { res[i] = start; start = operator(start, step); } return res; }

See also

  map() , foreach()