<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
  <refentry id="function.range">
   <refnamediv>
    <refname>range</refname>
    <refpurpose>
     Create an array containing a range of elements
    </refpurpose>
   </refnamediv>
   <refsect1>
   <title>Description</title>
    <methodsynopsis>
     <type>array</type><methodname>range</methodname>
     <methodparam><type>int</type><parameter>low</parameter></methodparam>
     <methodparam><type>int</type><parameter>high</parameter></methodparam>
     <methodparam choice="opt"><type>int</type><parameter>step</parameter></methodparam>
    </methodsynopsis>
    <para>
     <function>range</function> returns an array of elements from
     <parameter>low</parameter> to <parameter>high</parameter>,
     inclusive.  If low > high, the sequence will be from high to low.
    </para>
    <note>
     <title>New parameter</title>
     <simpara>
      The optional <parameter>step</parameter> parameter was added in 5.0.0.
     </simpara>
    </note>
    <para>
     If a <parameter>step</parameter> value is given, it will be used as the
     increment between elements in the sequence.  <parameter>step</parameter>
     should be given as a positive number.  If not specified,
     <parameter>step</parameter> will default to 1.
    </para>
    <para>
     <example>
      <title><function>range</function> examples</title>
      <programlisting role="php">
<![CDATA[
<?php
// array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ,11, 12)
foreach (range(0, 12) as $number) {
    echo $number;
}

// The step parameter was introduced in 5.0.0
// array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
foreach (range(0, 100, 10) as $number) {
    echo $number;
}

// Use of character sequences introduced in 4.1.0
// array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');
foreach (range('a', 'i') as $letter) {
    echo $letter;
}
// array('c', 'b', 'a');
foreach (range('c', 'a') as $letter) {
    echo $letter;
}
?>
]]>
      </programlisting>
     </example>
    </para>
    <note>
     <para>
      Prior to PHP version 4.1.0, <function>range</function> only generated
      incrementing integer arrays.  Support for character sequences and
      decrementing arrays was added in 4.1.0.  Character sequence values
      are limited to a length of one.  If a length greater than one is
      entered, only the first character is used.
     </para>
    </note>
    <caution>
     <para>
      In PHP versions 4.1.0 through 4.3.2, <function>range</function> sees
      numeric strings as strings and not integers.  Instead, they will be
      used for character sequences.  For example, <literal>"4242"</literal>
      is treated as <literal>"4"</literal>.
     </para>
    </caution>
    <para>
     See also <function>shuffle</function>,
     <function>array_fill</function>, and
     <link linkend="control-structures.foreach">foreach</link>.
    </para>
   </refsect1>
  </refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->