function.array-multisort.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 289 行 · 第 1/2 页
HTML
289 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Sort multiple or multi-dimensional arrays</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-merge.html">array_merge</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.array-pad.html">array_pad</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.array-multisort" class="refentry"> <div class="refnamediv"> <h1 class="refname">array_multisort</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">array_multisort</span> — <span class="dc-title">Sort multiple or multi-dimensional arrays</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>array_multisort</b></b></span> ( <span class="methodparam"><span class="type">array</span> <tt class="parameter">$arr</tt></span> [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$arg</tt></span> [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$...</tt></span> ]] )</div> <p class="para rdfs-comment"> <b>array_multisort()</b> can be used to sort several arrays at once, or a multi-dimensional array by one or more dimensions. </p> <p class="para"> Associative (<a href="language.types.string.html" class="type string">string</a>) keys will be maintained, but numeric keys will be re-indexed. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">arr</tt></i></span> <dd> <p class="para"> An <a href="language.types.array.html" class="type array">array</a> being sorted. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">arg</tt></i></span> <dd> <p class="para"> Optionally another <a href="language.types.array.html" class="type array">array</a>, or sort options for the previous <a href="language.types.array.html" class="type array">array</a> argument: <b><tt>SORT_ASC</tt></b>, <b><tt>SORT_DESC</tt></b>, <b><tt>SORT_REGULAR</tt></b>, <b><tt>SORT_NUMERIC</tt></b>, <b><tt>SORT_STRING</tt></b>. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">...</tt></i></span> <dd> <p class="para"> Additional <i><tt class="parameter">arg</tt></i>'s. </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 Sorting multiple arrays</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$ar1 </span><span style="color: #007700">= array(</span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #0000BB">100</span><span style="color: #007700">, </span><span style="color: #0000BB">100</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$ar2 </span><span style="color: #007700">= array(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">3</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">);<br /></span><span style="color: #0000BB">array_multisort</span><span style="color: #007700">(</span><span style="color: #0000BB">$ar1</span><span style="color: #007700">, </span><span style="color: #0000BB">$ar2</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$ar1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$ar2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p> In this example, after sorting, the first array will contain 0, 10, 100, 100. The second array will contain 4, 1, 2, 3. The entries in the second array corresponding to the identical entries in the first array (100 and 100) were sorted as well. </p></div> <div class="example-contents"><pre><div class="cdata"><pre>array(4) { [0]=> int(0) [1]=> int(10) [2]=> int(100) [3]=> int(100)}array(4) { [0]=> int(4) [1]=> int(1) [2]=> int(2) [3]=> int(3)}</pre></div> </pre></div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #2 Sorting multi-dimensional array</b></p> <div class="example-contents">
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?