mirror of
https://github.com/php/doc-zh.git
synced 2026-03-24 07:02:15 +01:00
215 lines
5.0 KiB
XML
Executable File
215 lines
5.0 KiB
XML
Executable File
<?xml version="1.0" encoding="utf-8"?>
|
||
<!-- $Revision$ -->
|
||
<!-- EN-Revision: 2e60c5134e7a847c99f81eb3f7ecee1f5efeeace Maintainer: dallas Status: ready -->
|
||
<!-- CREDITS: mowangjuanzi -->
|
||
<refentry xml:id="function.array-fill" xmlns="http://docbook.org/ns/docbook">
|
||
<refnamediv>
|
||
<refname>array_fill</refname>
|
||
<refpurpose>用给定的值填充数组</refpurpose>
|
||
</refnamediv>
|
||
|
||
<refsect1 role="description">
|
||
&reftitle.description;
|
||
<methodsynopsis>
|
||
<type>array</type><methodname>array_fill</methodname>
|
||
<methodparam><type>int</type><parameter>start_index</parameter></methodparam>
|
||
<methodparam><type>int</type><parameter>count</parameter></methodparam>
|
||
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
|
||
</methodsynopsis>
|
||
<para>
|
||
用 <parameter>value</parameter> 参数的值填充 <parameter>count</parameter> 个元素到数组,
|
||
开始键名由 <parameter>start_index</parameter> 参数指定。
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="parameters">
|
||
&reftitle.parameters;
|
||
<para>
|
||
<variablelist>
|
||
|
||
<varlistentry>
|
||
<term><parameter>start_index</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
返回的数组的第一个索引值。
|
||
</para>
|
||
<para>
|
||
如果 <parameter>start_index</parameter> 是负数,在 PHP 8.0.0
|
||
之前,返回的数组的第一个索引是 <parameter>start_index</parameter>,
|
||
而后面索引则从 0 开始;自 PHP 8.0.0 起,
|
||
负数键将会正常递增。(参见 <link linkend="function.array-fill.example.basic">例子</link>)
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
|
||
<varlistentry>
|
||
<term><parameter>count</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
要插入元素的数量。必须大于或等于 0 且小于或等于 <literal>2147483647</literal>。
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
|
||
<varlistentry>
|
||
<term><parameter>value</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
用来填充的值。
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
|
||
</variablelist>
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="returnvalues">
|
||
&reftitle.returnvalues;
|
||
<para>
|
||
返回填充后的数组。
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="errors">
|
||
&reftitle.errors;
|
||
<para>
|
||
如果 <parameter>count</parameter> 超出范围,将会抛出 <classname>ValueError</classname>。
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="changelog">
|
||
&reftitle.changelog;
|
||
<informaltable>
|
||
<tgroup cols="2">
|
||
<thead>
|
||
<row>
|
||
<entry>&Version;</entry>
|
||
<entry>&Description;</entry>
|
||
</row>
|
||
</thead>
|
||
<tbody>
|
||
<row>
|
||
<entry>8.0.0</entry>
|
||
<entry>
|
||
如果 <function>array_fill</function> 的 <parameter>count</parameter>
|
||
超出范围现在将会抛出 <classname>ValueError</classname>,
|
||
之前会引发 <constant>E_WARNING</constant> 且函数返回 &false;。
|
||
</entry>
|
||
</row>
|
||
</tbody>
|
||
</tgroup>
|
||
</informaltable>
|
||
</refsect1>
|
||
|
||
<refsect1 role="examples">
|
||
&reftitle.examples;
|
||
<para>
|
||
<example xml:id="function.array-fill.example.basic">
|
||
<title><function>array_fill</function> 示例</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
$a = array_fill(5, 6, 'banana');
|
||
print_r($a);
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
&example.outputs;
|
||
<screen>
|
||
<![CDATA[
|
||
Array
|
||
(
|
||
[5] => banana
|
||
[6] => banana
|
||
[7] => banana
|
||
[8] => banana
|
||
[9] => banana
|
||
[10] => banana
|
||
)
|
||
]]>
|
||
</screen>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
<example xml:id="function.array-fill.example.negative-start-index">
|
||
<title>开始索引为负数的 <function>array_fill</function> 示例</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
$a = array_fill(-2, 4, 'pear');
|
||
print_r($a);
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
&example.outputs.8;
|
||
<screen>
|
||
<![CDATA[
|
||
Array
|
||
(
|
||
[-2] => pear
|
||
[-1] => pear
|
||
[0] => pear
|
||
[1] => pear
|
||
)
|
||
]]>
|
||
</screen>
|
||
&example.outputs.7;
|
||
<screen>
|
||
<![CDATA[
|
||
Array
|
||
(
|
||
[-2] => pear
|
||
[0] => pear
|
||
[1] => pear
|
||
[2] => pear
|
||
)
|
||
]]>
|
||
</screen>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
注意 索引 <literal>-1</literal> 在 PHP 8.0.0 之前不存在。
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="notes">
|
||
&reftitle.notes;
|
||
<para>
|
||
参见手册上<link linkend="language.types.array">数组</link>一节里关于负数的键的详细解释。
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="seealso">
|
||
&reftitle.seealso;
|
||
<para>
|
||
<simplelist>
|
||
<member><function>array_fill_keys</function></member>
|
||
<member><function>str_repeat</function></member>
|
||
<member><function>range</function></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
|
||
-->
|