📄 function.arsort.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Sort an array in reverse order and maintain index association</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.array.html">array</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.asort.html">asort</a></div> <div class="up"><a href="ref.array.html">Array Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.arsort" class="refentry"> <div class="refnamediv"> <h1 class="refname">arsort</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">arsort</span> — <span class="dc-title">Sort an array in reverse order and maintain index association</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><b>arsort</b></b></span> ( <span class="methodparam"><span class="type">array</span> <tt class="parameter reference">&$array</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$sort_flags</tt></span> ] )</div> <p class="para rdfs-comment"> This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. </p> <p class="para"> This is used mainly when sorting associative arrays where the actual element order is significant. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">array</tt></i></span> <dd> <p class="para"> The input array. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">sort_flags</tt></i></span> <dd> <p class="para"> You may modify the behavior of the sort using the optional parameter <i><tt class="parameter">sort_flags</tt></i>, for details see <a href="function.sort.html" class="function">sort()</a>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>arsort()</b> example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$fruits </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"d" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"lemon"</span><span style="color: #007700">, </span><span style="color: #DD0000">"a" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"orange"</span><span style="color: #007700">, </span><span style="color: #DD0000">"b" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"banana"</span><span style="color: #007700">, </span><span style="color: #DD0000">"c" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"apple"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">arsort</span><span style="color: #007700">(</span><span style="color: #0000BB">$fruits</span><span style="color: #007700">);<br />foreach (</span><span style="color: #0000BB">$fruits </span><span style="color: #007700">as </span><span style="color: #0000BB">$key </span><span style="color: #007700">=> </span><span style="color: #0000BB">$val</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"$key = $val\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents"><pre><div class="cdata"><pre>a = oranged = lemonb = bananac = apple</pre></div> </pre></div> <div class="example-contents"><p> The fruits have been sorted in reverse alphabetical order, and the index associated with each element has been maintained. </p></div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.asort.html" class="function" rel="rdfs-seeAlso">asort()</a></li> <li class="member"><a href="function.rsort.html" class="function" rel="rdfs-seeAlso">rsort()</a></li> <li class="member"><a href="function.ksort.html" class="function" rel="rdfs-seeAlso">ksort()</a></li> <li class="member"><a href="function.sort.html" class="function" rel="rdfs-seeAlso">sort()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.array.html">array</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.asort.html">asort</a></div> <div class="up"><a href="ref.array.html">Array Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -