2002-05-12 08:19:28 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2007-06-20 22:25:43 +00:00
|
|
|
<!-- $Revision: 1.15 $ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- splitted from ./en/functions/array.xml, last change in rev 1.25 -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xml:id="function.natsort" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
2006-10-31 11:24:02 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>natsort</refname>
|
|
|
|
<refpurpose>Sort an array using a "natural order" algorithm</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
<methodsynopsis>
|
|
|
|
<type>bool</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>
|
|
|
|
&return.success;
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>natsort</function> example</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
2002-07-14 01:16:48 +00:00
|
|
|
<?php
|
2003-08-17 12:21:03 +00:00
|
|
|
$array1 = $array2 = array("img12.png", "img10.png", "img2.png", "img1.png");
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
sort($array1);
|
|
|
|
echo "Standard sorting\n";
|
|
|
|
print_r($array1);
|
|
|
|
|
|
|
|
natsort($array2);
|
|
|
|
echo "\nNatural order sorting\n";
|
|
|
|
print_r($array2);
|
2002-07-14 01:16:48 +00:00
|
|
|
?>
|
2002-04-15 00:12:54 +00:00
|
|
|
]]>
|
2006-10-31 11:24:02 +00:00
|
|
|
</programlisting>
|
|
|
|
&example.outputs;
|
|
|
|
<screen>
|
2002-04-15 00:12:54 +00:00
|
|
|
<![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
|
|
|
|
)
|
|
|
|
]]>
|
2006-10-31 11:24:02 +00:00
|
|
|
</screen>
|
2002-04-15 00:12:54 +00:00
|
|
|
<para>
|
2007-06-20 22:25:43 +00:00
|
|
|
For more information see: Martin Pool's <link
|
|
|
|
xlink:href="&url.strnatcmp;">Natural Order String Comparison</link>
|
2006-10-31 11:24:02 +00:00
|
|
|
page.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
2006-10-31 11:24:02 +00:00
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
See also <function>natcasesort</function>,
|
|
|
|
<function>strnatcmp</function>, and
|
|
|
|
<function>strnatcasecmp</function>.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
<!-- 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
|
|
|
|
-->
|