mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 08:58:56 +00:00
range: provide examples of generating decrementing arrays and character ranges using array_reverse and array_map
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@65773 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
5e45f2efe5
commit
6947456d0d
1 changed files with 23 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.138 $ -->
|
||||
<!-- $Revision: 1.139 $ -->
|
||||
<reference id="ref.array">
|
||||
<title>Array Functions</title>
|
||||
<titleabbrev>Arrays</titleabbrev>
|
||||
|
@ -3137,9 +3137,10 @@ Array
|
|||
<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.
|
||||
<example>
|
||||
<title><function>range</function> examples</title>
|
||||
<programlisting role="php">
|
||||
</para>
|
||||
<example>
|
||||
<title><function>range</function> examples</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
foreach(range(0, 9) as $number) {
|
||||
echo $number;
|
||||
|
@ -3151,15 +3152,30 @@ foreach(range('z', 'a') as $letter) {
|
|||
echo $letter;
|
||||
}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
</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.
|
||||
|
|
Loading…
Reference in a new issue