mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 17:08:54 +00:00
added natsort() and natcasesort()
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@30927 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
0ba16b3425
commit
084cf8438f
1 changed files with 114 additions and 0 deletions
|
@ -1823,6 +1823,120 @@ while (list ($id, $name, $salary) = mysql_fetch_row ($result)) {
|
|||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.natsort">
|
||||
<refnamediv>
|
||||
<refname>natsort</refname>
|
||||
<refpurpose>
|
||||
Sort an array using a "natural order" algorithm
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>void <function>natsort</function></funcdef>
|
||||
<paramdef>array <parameter>array</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
This function implements a sort algorithm that orders
|
||||
alphanumeric strings in the way a human being would. 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">
|
||||
$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>
|
||||
</para>
|
||||
<para>
|
||||
The code above will generate the following output:
|
||||
</para>
|
||||
<para>
|
||||
<informalexample>
|
||||
<programlisting>
|
||||
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
|
||||
)
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
For more infomation see: Martin Pool's <ulink
|
||||
url="&url.strnatcmp;">Natural Order String Comparison</ulink>
|
||||
page.
|
||||
</para>
|
||||
<para>
|
||||
See also <function>natcasesort</function>,
|
||||
<function>strnatcmp</function> and
|
||||
<function>strnatcasecmp</function>.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.natcasesort">
|
||||
<refnamediv>
|
||||
<refname>natcasesort</refname>
|
||||
<refpurpose>
|
||||
Sort an array using a case insensitive "natural order" algorithm
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>void <function>natcasesort</function></funcdef>
|
||||
<paramdef>array <parameter>array</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
This function implements a sort algorithm that orders
|
||||
alphanumeric strings in the way a human being would. This is
|
||||
described as a "natural ordering".
|
||||
</para>
|
||||
<para>
|
||||
<function>natcasesort</function> is a case insensitive version of
|
||||
<function>natsort</function>. See <function>natsort</function>
|
||||
for an example of the difference between this algorithm and the
|
||||
regular computer string sorting algorithms.
|
||||
</para>
|
||||
<para>
|
||||
For more infomation see: Martin Pool's <ulink
|
||||
url="&url.strnatcmp;">Natural Order String Comparison</ulink>
|
||||
page.
|
||||
</para>
|
||||
<para>
|
||||
See also <function>natsort</function>,
|
||||
<function>strnatcmp</function> and
|
||||
<function>strnatcasecmp</function>.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.next">
|
||||
<refnamediv>
|
||||
<refname>next</refname>
|
||||
|
|
Loading…
Reference in a new issue