1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-26 08:02:16 +01:00
Files
archived-doc-zh/reference/array/functions/range.xml
Dallas Wang cc964efcd6 Translation completed.
git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@95704 c90b9560-bf6c-de11-be94-00142212c4b1
2002-09-14 20:32:59 +00:00

88 lines
2.2 KiB
XML
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="gb2312"?>
<!-- $Revision: 1.1 $ -->
<!-- $Author: dallas $ -->
<!-- EN-Revision: 1.4 Maintainer: dallas Status: ready -->
<refentry id="function.range">
<refnamediv>
<refname>range</refname>
<refpurpose>
建立一个包含指定范围单元的数组
</refpurpose>
</refnamediv>
<refsect1>
<title>说明</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> 返回数组中从
<parameter>low</parameter><parameter>high</parameter> 的单元,包括它们本身。如果
low > high则序列将从 high 到 low。
</para>
<example>
<title><function>range</function> 例子</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>
在版本 4.1.0 之前 <function>range</function>
函数只产生递增的整数数组。对于字符序列和递减数组的支持是 4.1.0 加入的。
</para>
<example>
<title>模拟递减序列和字符序列</title>
<programlisting role="php">
<![CDATA[
# array_reverse 可以用来调换 range 的顺序
foreach(array_reverse(range(0,9)) as $number) {
echo $number;
}
# array_map() 可以用 chr() 将整数转换成字符
foreach(array_map('chr', range(ord('a'),ord('z'))) as $character) {
echo $character;
}
]]>
</programlisting>
</example>
</note>
<para>
另一个使用的例子参见 <function>shuffle</function>
</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
-->