php-doc-en/reference/array/functions/range.xml
Daniel Egeberg 96c9d88bad Converted to utf-8
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@297028 c90b9560-bf6c-de11-be94-00142212c4b1
2010-03-28 22:10:10 +00:00

169 lines
4.5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.range" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>range</refname>
<refpurpose>Create an array containing a range of elements</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>range</methodname>
<methodparam><type>mixed</type><parameter>low</parameter></methodparam>
<methodparam><type>mixed</type><parameter>high</parameter></methodparam>
<methodparam choice="opt"><type>number</type><parameter>step</parameter></methodparam>
</methodsynopsis>
<para>
Create an array containing a range of elements.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>low</parameter></term>
<listitem>
<para>
Low value.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>high</parameter></term>
<listitem>
<para>
High value.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>step</parameter></term>
<listitem>
<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>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
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>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.0.0</entry>
<entry>
The optional <parameter>step</parameter> parameter was added.
</entry>
</row>
<row>
<entry>4.1.0 to 4.3.2</entry>
<entry>
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>.
</entry>
</row>
<row>
<entry>4.1.0</entry>
<entry>
Prior to PHP 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.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<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>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>shuffle</function></member>
<member><function>array_fill</function></member>
<member>&foreach;</member>
</simplelist>
</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:"~/.phpdoc/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
-->