uTools-Manuals/docs/php/shuffle.html
2019-04-08 23:22:26 +08:00

123 lines
4.8 KiB
HTML
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.

<!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.shuffle" class="refentry">
<div class="refnamediv">
<h1 class="refname">shuffle</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">shuffle</span> &mdash; <span class="dc-title">打乱数组</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.shuffle-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>shuffle</strong></span>
( <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$array</code></span>
) : <span class="type">bool</span></div>
<p class="para rdfs-comment">
本函数打乱(随机排列单元的顺序)一个数组。
它使用的是伪随机数产生器,并不适合密码学的场合。
</p>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
If two members compare as equal, their relative order in the sorted array is undefined.
</p>
</p></blockquote>
</div>
<div class="refsect1 parameters" id="refsect1-function.shuffle-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">array</code></dt>
<dd>
<p class="para">
待操作的数组。
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.shuffle-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
成功时返回 <strong><code>TRUE</code></strong> 或者在失败时返回 <strong><code>FALSE</code></strong>
</p>
</div>
<div class="refsect1 changelog" id="refsect1-function.shuffle-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>7.1.0</td>
<td>
<a href="migration71.incompatible.html#migration71.incompatible.rand_srand_aliases" class="link">内置的随机数产生算法从 libc rand 函数改成 <a href="http://www.math.sci.hiroshima_u.ac.jp/~m_mat/MT/emt.html" class="link external">&raquo;&nbsp;梅森旋转</a>伪随机数生成算法。</a>
</td>
</tr>
</tbody>
</table>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.shuffle-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-6117">
<p><strong>Example #1 <span class="function"><strong>shuffle()</strong></span> 例子</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$numbers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">range</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">shuffle</span><span style="color: #007700">(</span><span style="color: #0000BB">$numbers</span><span style="color: #007700">);<br />foreach&nbsp;(</span><span style="color: #0000BB">$numbers&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$number</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$number</span><span style="color: #DD0000">&nbsp;"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.shuffle-notes">
<h3 class="title">注释</h3>
<blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数为 <code class="parameter">array</code>
中的元素赋与新的键名。这将删除原有的键名,而不是仅仅将键名重新排序。</span></p></blockquote>
</div>
<div class="refsect1 seealso" id="refsect1-function.shuffle-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="array_rand.html" class="function" rel="rdfs-seeAlso">array_rand()</a> - 从数组中随机取出一个或多个单元</span></li>
<li class="member"><a href="array.sorting.html" class="link">数组排序函数对比</a></li>
</ul>
</p>
</div>
</div></div></div></body></html>