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

120 lines
5.2 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.rsort" class="refentry">
<div class="refnamediv">
<h1 class="refname">rsort</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">rsort</span> &mdash; <span class="dc-title">对数组逆向排序</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.rsort-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>rsort</strong></span>
( <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$array</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$sort_flags</code><span class="initializer"> = SORT_REGULAR</span></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.rsort-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">array</code></dt>
<dd>
<p class="para">
输入的数组。
</p>
</dd>
<dt>
<code class="parameter">sort_flags</code></dt>
<dd>
<p class="para">
可以用可选参数 <code class="parameter">sort_flags</code>
改变排序的行为,详情见 <span class="function"><a href="sort.html" class="function">sort()</a></span>
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.rsort-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
成功时返回 <strong><code>TRUE</code></strong> 或者在失败时返回 <strong><code>FALSE</code></strong>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.rsort-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-6116">
<p><strong>Example #1 <span class="function"><strong>rsort()</strong></span></strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fruits&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"lemon"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"orange"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"banana"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"apple"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">rsort</span><span style="color: #007700">(</span><span style="color: #0000BB">$fruits</span><span style="color: #007700">);<br />foreach&nbsp;(</span><span style="color: #0000BB">$fruits&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$key</span><span style="color: #DD0000">&nbsp;=&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
0 = orange
1 = lemon
2 = banana
3 = apple
</pre></div>
</div>
<div class="example-contents"><p>
fruits 被按照字母顺序逆向排序。
</p></div>
</div>
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.rsort-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.rsort-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="arsort.html" class="function" rel="rdfs-seeAlso">arsort()</a> - 对数组进行逆向排序并保持索引关系</span></li>
<li class="member"><span class="function"><a href="krsort.html" class="function" rel="rdfs-seeAlso">krsort()</a> - 对数组按照键名逆向排序</span></li>
<li class="member"><a href="array.sorting.html" class="link">数组排序函数对比</a></li>
</ul>
</p>
</div>
</div></div></div></body></html>