mirror of
https://github.com/php/doc-zh.git
synced 2026-03-26 08:02:16 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@95504 c90b9560-bf6c-de11-be94-00142212c4b1
130 lines
4.2 KiB
XML
130 lines
4.2 KiB
XML
<?xml version="1.0" encoding="gb2312"?>
|
||
<!-- $Revision: 1.1 $ -->
|
||
<!-- $Author: dallas $ -->
|
||
<!-- EN-Revision: 1.4 Maintainer: dallas Status: ready -->
|
||
<refentry id="function.array-multisort">
|
||
<refnamediv>
|
||
<refname>array_multisort</refname>
|
||
<refpurpose>对多个数组或多维数组进行排序</refpurpose>
|
||
</refnamediv>
|
||
<refsect1>
|
||
<title>说明</title>
|
||
<methodsynopsis>
|
||
<type>bool</type><methodname>array_multisort</methodname>
|
||
<methodparam><type>array</type><parameter>ar1</parameter></methodparam>
|
||
<methodparam choice="opt"><type>mixed</type><parameter>arg</parameter></methodparam>
|
||
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
|
||
<methodparam choice="opt"><type>array</type><parameter>...</parameter></methodparam>
|
||
</methodsynopsis>
|
||
<para>
|
||
<function>array_multisort</function> 可以用来一次对多个数组进行排序或者根据某一维对多维数组进行排序。排序时保留原有的键名关联。
|
||
</para>
|
||
<para>
|
||
输入数组被当成一个将以行来排序的表的列 - 这类似于 SQL 的 ORDER BY
|
||
子句的功能。第一个数组是要排序的主要数组。
|
||
The input arrays are treated as columns of a table to be sorted
|
||
by rows - this resembles the functionality of SQL ORDER BY
|
||
clause. The first array is the primary one to sort by. The rows
|
||
(values) in that array that compare the same are sorted by the
|
||
next input array, and so on.
|
||
</para>
|
||
<para>
|
||
The argument structure of this function is a bit unusual, but
|
||
flexible. The very first argument has to be an
|
||
array. Subsequently, each argument can be either an array or a
|
||
sorting flag from the following lists.
|
||
</para>
|
||
<para>
|
||
Sorting order flags:
|
||
<itemizedlist>
|
||
<listitem>
|
||
<simpara>SORT_ASC - sort in ascending order</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>SORT_DESC - sort in descending order</simpara>
|
||
</listitem>
|
||
</itemizedlist>
|
||
</para>
|
||
<para>
|
||
Sorting type flags:
|
||
<itemizedlist>
|
||
<listitem>
|
||
<simpara>SORT_REGULAR - compare items normally</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>SORT_NUMERIC - compare items numerically</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>SORT_STRING - compare items as strings</simpara>
|
||
</listitem>
|
||
</itemizedlist>
|
||
</para>
|
||
<para>
|
||
No two sorting flags of the same type can be specified after each
|
||
array. The sorting flags specified after an array argument apply
|
||
only to that array - they are reset to default SORT_ASC and
|
||
SORT_REGULAR after before each new array argument.
|
||
</para>
|
||
<para>
|
||
&return.success;
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title>Sorting multiple arrays</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
$ar1 = array ("10", 100, 100, "a");
|
||
$ar2 = array (1, 3, "2", 1);
|
||
array_multisort ($ar1, $ar2);
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
In this example, after sorting, the first array will contain 10,
|
||
"a", 100, 100. The second array will contain 1, 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.
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title>Sorting multi-dimensional array</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1));
|
||
array_multisort ($ar[0], SORT_ASC, SORT_STRING,
|
||
$ar[1], SORT_NUMERIC, SORT_DESC);
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
In this example, after sorting, the first array will contain 10,
|
||
100, 100, "a" (it was sorted as strings in ascending order), and
|
||
the second one will contain 1, 3, "2", 1 (sorted as numbers, in
|
||
descending order).
|
||
</para>
|
||
</refsect1>
|
||
</refentry>
|
||
|
||
<!-- Keep this comment at the end of the file
|
||
Local variables:
|
||
mode: sgml
|
||
sgml-omittag:t
|
||
sgml-shorttag:t
|
||
sgml-minimize-attributes:nil
|
||
sgml-always-quote-attributes:t
|
||
sgml-indent-step:1
|
||
sgml-indent-data:t
|
||
indent-tabs-mode:nil
|
||
sgml-parent-document:nil
|
||
sgml-default-dtd-file:"../../../../manual.ced"
|
||
sgml-exposed-tags:nil
|
||
sgml-local-catalogs:nil
|
||
sgml-local-ecat-files:nil
|
||
End:
|
||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||
vim: et tw=78 syn=sgml
|
||
vi: ts=1 sw=1
|
||
-->
|