Back to Select class

Method integerlist

public static string
integerlist
(mixed $start, mixed $end, mixed $inc, mixed $name, mixed $attribs = null, mixed $selected = null, mixed $format = '')
Generates a selection list of integers.
Parameters
  • int $start The start integer
  • int $end The end integer
  • int $inc The increment
  • string $name The value of the HTML name attribute
  • mixed $attribs Additional HTML attributes for the `<select>` tag, an array of attributes, or an array of options. Treated as options if it is the last argument passed.
  • mixed $selected The key that is selected
  • string $format The printf format to be applied to the number
Returns
  • string HTML for the select list
Since
  • 1.5
Class: Select
Project: Joomla

Method integerlist - Source code

/**
 * Generates a selection list of integers.
 *
 * @param   integer  $start     The start integer
 * @param   integer  $end       The end integer
 * @param   integer  $inc       The increment
 * @param   string   $name      The value of the HTML name attribute
 * @param   mixed    $attribs   Additional HTML attributes for the `<select>` tag, an array of
 *                              attributes, or an array of options. Treated as options if it is the last
 *                              argument passed.
 * @param   mixed    $selected  The key that is selected
 * @param   string   $format    The printf format to be applied to the number
 *
 * @return  string   HTML for the select list
 *
 * @since   1.5
 */
public static function integerlist($start, $end, $inc, $name, $attribs = null, $selected = null, $format = '')
{
    // Set default options
    $options = array_merge(HTMLHelper::$formatOptions, array('format.depth' => 0, 'option.format' => '', 'id' => false));
    if (is_array($attribs) && func_num_args() === 5) {
        // Assume we have an options array
        $options = array_merge($options, $attribs);
        // Extract the format and remove it from downstream options
        $format = $options['option.format'];
        unset($options['option.format']);
    } else {
        // Get options from the parameters
        $options['list.attr'] = $attribs;
        $options['list.select'] = $selected;
    }
    $start = (int) $start;
    $end = (int) $end;
    $inc = (int) $inc;
    $data = array();
    for ($i = $start; $i <= $end; $i += $inc) {
        $data[$i] = $format ? sprintf($format, $i) : $i;
    }
    // Tell genericlist() to use array keys
    $options['option.key'] = null;
    return HTMLHelper::_('select.genericlist', $data, $name, $options);
}