php-doc-en/reference/array/functions/range.xml

88 lines
2.4 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<!-- 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>mixed</type><parameter>low</parameter></methodparam>
<methodparam><type>mixed</type><parameter>high</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>
<example>
<title><function>range</function> examples</title>
<programlisting role="php">
<![CDATA[
foreach(range(0, 9) as $number) {
echo $number;
}
foreach(range('a', 'z') as $letter) {
echo $letter;
}
foreach(range('z', 'a') as $letter) {
echo $letter;
}
]]>
</programlisting>
</example>
<note>
<para>
Prior to version 4.1.0 the <function>range</function> function
only generated incrementing integer arrays. Support for
character sequences and decrementing arrays was added in 4.1.0.
</para>
<example>
<title>Simulating decrementing ranges and character sequences</title>
<programlisting role="php">
<![CDATA[
# array_reverse can be used to flip the order of a range
foreach(array_reverse(range(0,9)) as $number) {
echo $number;
}
# array_map() can be used to turn integers into characters using chr()
foreach(array_map('chr', range(ord('a'),ord('z'))) as $character) {
echo $character;
}
]]>
</programlisting>
</example>
</note>
<para>
See <function>shuffle</function> for another example of its use.
</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
-->