mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
194 lines
6.7 KiB
HTML
194 lines
6.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
<title>用给定的值填充数组</title>
|
||
</head>
|
||
<body class="docs"><div id="layout">
|
||
<div id="layout-content"><div id="function.array-fill" class="refentry">
|
||
<div class="refnamediv">
|
||
<h1 class="refname">array_fill</h1>
|
||
<p class="verinfo">(PHP 4 >= 4.2.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">array_fill</span> — <span class="dc-title">用给定的值填充数组</span></p>
|
||
|
||
</div>
|
||
|
||
<div class="refsect1 description" id="refsect1-function.array-fill-description">
|
||
<h3 class="title">说明</h3>
|
||
<div class="methodsynopsis dc-description">
|
||
<span class="methodname"><strong>array_fill</strong></span>
|
||
( <span class="methodparam"><span class="type">int</span> <code class="parameter">$start_index</code></span>
|
||
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$num</code></span>
|
||
, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
|
||
) : <span class="type">array</span></div>
|
||
|
||
<p class="para rdfs-comment">
|
||
<span class="function"><strong>array_fill()</strong></span> 用 <code class="parameter">value</code>
|
||
参数的值将一个数组填充 <code class="parameter">num</code> 个条目,键名由
|
||
<code class="parameter">start_index</code> 参数指定的开始。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 parameters" id="refsect1-function.array-fill-parameters">
|
||
<h3 class="title">参数</h3>
|
||
<p class="para">
|
||
<dl>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">start_index</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
返回的数组的第一个索引值。
|
||
</p>
|
||
<p class="para">
|
||
如果 <code class="parameter">start_index</code> 是负数,
|
||
那么返回的数组的第一个索引将会是
|
||
<code class="parameter">start_index</code> ,而后面索引则从0开始。
|
||
(参见 <a href="array-fill.html#function.array-fill.example.basic" class="link">例子</a>)。
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">num</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
插入元素的数量。
|
||
必须大于或等于 0。
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">value</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
用来填充的值。
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
|
||
</dl>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 returnvalues" id="refsect1-function.array-fill-returnvalues">
|
||
<h3 class="title">返回值</h3>
|
||
<p class="para">
|
||
返回填充后的数组。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 errors" id="refsect1-function.array-fill-errors">
|
||
<h3 class="title">错误/异常</h3>
|
||
<p class="para">
|
||
如果 <code class="parameter">num</code> 小于零,将会抛出 <strong><code>E_WARNING</code></strong>。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 changelog" id="refsect1-function.array-fill-changelog">
|
||
<h3 class="title">更新日志</h3>
|
||
<p class="para">
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>版本</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td>5.6.0</td>
|
||
<td>
|
||
<code class="parameter">num</code> 现在可以是零。
|
||
之前
|
||
<code class="parameter">num</code> 必须大于零。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 examples" id="refsect1-function.array-fill-examples">
|
||
<h3 class="title">范例</h3>
|
||
<p class="para">
|
||
<div class="example" id="example-6026">
|
||
<p><strong>Example #1 <span class="function"><strong>array_fill()</strong></span> 例子</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?php<br />$a </span><span style="color: #007700">= </span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(</span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #0000BB">6</span><span style="color: #007700">, </span><span style="color: #DD0000">'banana'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$b </span><span style="color: #007700">= </span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(-</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">4</span><span style="color: #007700">, </span><span style="color: #DD0000">'pear'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$b</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
<div class="example-contents"><p>以上例程会输出:</p></div>
|
||
<div class="example-contents screen">
|
||
<div class="cdata"><pre>
|
||
Array
|
||
(
|
||
[5] => banana
|
||
[6] => banana
|
||
[7] => banana
|
||
[8] => banana
|
||
[9] => banana
|
||
[10] => banana
|
||
)
|
||
Array
|
||
(
|
||
[-2] => pear
|
||
[0] => pear
|
||
[1] => pear
|
||
[2] => pear
|
||
)
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 notes" id="refsect1-function.array-fill-notes">
|
||
<h3 class="title">注释</h3>
|
||
<p class="para">
|
||
参见手册上 <a href="language.types.array.html" class="link">数组</a> 一节里关于负数的键的详细解释。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 seealso" id="refsect1-function.array-fill-seealso">
|
||
<h3 class="title">参见</h3>
|
||
<p class="para">
|
||
<ul class="simplelist">
|
||
<li class="member"><span class="function"><a href="array_fill_keys.html" class="function" rel="rdfs-seeAlso">array_fill_keys()</a> - 使用指定的键和值填充数组</span></li>
|
||
<li class="member"><span class="function"><a href="str_repeat.html" class="function" rel="rdfs-seeAlso">str_repeat()</a> - 重复一个字符串</span></li>
|
||
<li class="member"><span class="function"><a href="range.html" class="function" rel="rdfs-seeAlso">range()</a> - 根据范围创建数组,包含指定的元素</span></li>
|
||
</ul>
|
||
</p>
|
||
</div>
|
||
|
||
</div></div></div></body></html> |