php-doc-en/reference/array/functions/natsort.xml
2004-11-10 08:30:50 +00:00

99 lines
2.4 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.25 -->
<refentry id="function.natsort">
<refnamediv>
<refname>natsort</refname>
<refpurpose>
Sort an array using a "natural order" algorithm
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>void</type><methodname>natsort</methodname>
<methodparam><type>array</type><parameter role="reference">array</parameter></methodparam>
</methodsynopsis>
<para>
This function implements a sort algorithm that orders
alphanumeric strings in the way a human being would while maintaining
key/value associations. This is described as a "natural ordering". An
example of the difference between this algorithm and the regular computer
string sorting algorithms (used in <function>sort</function>) can be seen
below:
</para>
<para>
<example>
<title><function>natsort</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$array1 = $array2 = array("img12.png", "img10.png", "img2.png", "img1.png");
sort($array1);
echo "Standard sorting\n";
print_r($array1);
natsort($array2);
echo "\nNatural order sorting\n";
print_r($array2);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Standard sorting
Array
(
[0] => img1.png
[1] => img10.png
[2] => img12.png
[3] => img2.png
)
Natural order sorting
Array
(
[3] => img1.png
[2] => img2.png
[1] => img10.png
[0] => img12.png
)
]]>
</screen>
<para>
For more information see: Martin Pool's <ulink
url="&url.strnatcmp;">Natural Order String Comparison</ulink>
page.
</para>
</example>
</para>
<para>
See also <function>natcasesort</function>,
<function>strnatcmp</function>, and
<function>strnatcasecmp</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
-->