mirror of
https://github.com/php/doc-zh.git
synced 2026-04-25 00:58:02 +02:00
cc964efcd6
git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@95704 c90b9560-bf6c-de11-be94-00142212c4b1
104 lines
2.6 KiB
XML
Executable File
104 lines
2.6 KiB
XML
Executable File
<?xml version="1.0" encoding="gb2312"?>
|
||
<!-- $Revision: 1.1 $ -->
|
||
<!-- $Author: dallas $ -->
|
||
<!-- EN-Revision: 1.4 Maintainer: dallas Status: ready -->
|
||
<refentry id="function.sort">
|
||
<refnamediv>
|
||
<refname>sort</refname>
|
||
<refpurpose>对数组排序</refpurpose>
|
||
</refnamediv>
|
||
<refsect1>
|
||
<title>说明</title>
|
||
<methodsynopsis>
|
||
<type>void</type><methodname>sort</methodname>
|
||
<methodparam><type>array</type><parameter>array</parameter></methodparam>
|
||
<methodparam choice="opt"><type>int</type><parameter>sort_flags</parameter></methodparam>
|
||
</methodsynopsis>
|
||
<para>
|
||
本函数对数组进行排序。当本函数结束时数组单元将被从最低到最高重新安排。
|
||
<example>
|
||
<title><function>sort</function> 例子</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
|
||
$fruits = array ("lemon", "orange", "banana", "apple");
|
||
sort ($fruits);
|
||
reset ($fruits);
|
||
while (list ($key, $val) = each ($fruits)) {
|
||
echo "fruits[".$key."] = ".$val."\n";
|
||
}
|
||
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
本例将显示:
|
||
</para>
|
||
<para>
|
||
<screen>
|
||
<![CDATA[
|
||
fruits[0] = apple
|
||
fruits[1] = banana
|
||
fruits[2] = lemon
|
||
fruits[3] = orange
|
||
]]>
|
||
</screen>
|
||
</para>
|
||
<para>
|
||
fruits 被按照字母顺序排序。
|
||
</para>
|
||
<para>
|
||
可选的第二个参数 <parameter>sort_flags</parameter>
|
||
可以用以下值改变排序的行为:
|
||
</para>
|
||
<para>
|
||
排序类型标记:
|
||
<itemizedlist>
|
||
<listitem>
|
||
<simpara>SORT_REGULAR - 正常比较单元</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>SORT_NUMERIC - 单元被作为数字来比较</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>SORT_STRING - 单元被作为字符串来比较</simpara>
|
||
</listitem>
|
||
</itemizedlist>
|
||
</para>
|
||
<para>
|
||
参见
|
||
<function>arsort</function>,<function>asort</function>,<function>ksort</function>,<function>natsort</function>,<function>natcasesort</function>,<function>rsort</function>,<function>usort</function>,<function>array_multisort</function>
|
||
和 <function>uksort</function>。
|
||
</para>
|
||
<note>
|
||
<para>
|
||
第二个参数是 PHP 4 新加的。
|
||
</para>
|
||
</note>
|
||
</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
|
||
-->
|