php-doc-en/reference/array/functions/sort.xml
2004-01-01 22:59:00 +00:00

116 lines
3.1 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.10 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
<refentry id="function.sort">
<refnamediv>
<refname>sort</refname>
<refpurpose>Sort an array</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</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>
This function sorts an array. Elements will be arranged from
lowest to highest when this function has completed.
</para>
<note>
<simpara>
This function assigns new keys for the elements in
<parameter>array</parameter>. It will remove any existing
keys you may have assigned, rather than just reordering the keys.
</simpara>
</note>
<para>
&return.success;
</para>
<para>
<example>
<title><function>sort</function> example</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>
<para>
This example would display:
</para>
<screen>
<![CDATA[
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
]]>
</screen>
</example>
</para>
<para>
The fruits have been sorted in alphabetical order.
</para>
<para>
The optional second parameter <parameter>sort_flags</parameter>
may be used to modify the sorting behavior using these values:
</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>
<note>
<para>
The second parameter was added in PHP 4.
</para>
</note>
<para>
See also <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>, and
<function>uksort</function>.
</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
-->