mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-21 03:18:55 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@166223 c90b9560-bf6c-de11-be94-00142212c4b1
122 lines
3.3 KiB
XML
122 lines
3.3 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.14 $ -->
|
|
<!-- 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><constant>SORT_REGULAR</constant> - compare items normally</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><constant>SORT_NUMERIC</constant> - compare items numerically</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><constant>SORT_STRING</constant> - compare items as strings</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
<note>
|
|
<para>
|
|
The second parameter was added in PHP 4.
|
|
</para>
|
|
</note>
|
|
<warning>
|
|
<simpara>
|
|
Be careful when sorting arrays with mixed types values because
|
|
<function>sort</function> can produce unpredictable results.
|
|
</simpara>
|
|
</warning>
|
|
<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
|
|
-->
|