cvs: phpdoc /en/reference/array/functions natcasesort.xml natsort.xml

From: Date: Thu, 26 Feb 2004 19:55:34 +0000
Subject: cvs: phpdoc /en/reference/array/functions natcasesort.xml natsort.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969359253@lists.php.net to get a copy of this message
irchtml Thu Feb 26 14:55:34 2004 EDT Modified files: /phpdoc/en/reference/array/functions natcasesort.xml natsort.xml Log: added example for natcasesort fix: natsort does in fact maintain key/value http://cvs.php.net/diff.php/phpdoc/en/reference/array/functions/natcasesort.xml?r1=1.4&r2=1.5&ty=u Index: phpdoc/en/reference/array/functions/natcasesort.xml diff -u phpdoc/en/reference/array/functions/natcasesort.xml:1.4 phpdoc/en/reference/array/functions/natcasesort.xml:1.5 --- phpdoc/en/reference/array/functions/natcasesort.xml:1.4 Sun May 12 04:19:28 2002 +++ phpdoc/en/reference/array/functions/natcasesort.xml Thu Feb 26 14:55:33 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <!-- splitted from ./en/functions/array.xml, last change in rev 1.25 --> <refentry id="function.natcasesort"> <refnamediv> @@ -16,19 +16,65 @@ </methodsynopsis> <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". + alphanumeric strings in the way a human being would while maintaining + key/value associations. 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. + <function>natsort</function>. </para> <para> - For more information see: Martin Pool's <ulink - url="&url.strnatcmp;">Natural Order String Comparison</ulink> - page. + <example> + <title><function>natcasesort</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php +$array1 = $array2 = array('IMG0.png', 'img12.png', 'img10.png', 'img2.png', 'img1.png', 'IMG3.png'); + +sort($array1); +echo "Standard sorting\n"; +print_r($array1); + +natcasesort($array2); +echo "\nNatural order sorting (case-insensitive)\n"; +print_r($array2); +?> +]]> + </programlisting> + <para> + The code above will generate the following output: + </para> + <screen> +<![CDATA[ +Standard sorting +Array +( + [0] => IMG0.png + [1] => IMG3.png + [2] => img1.png + [3] => img10.png + [4] => img12.png + [5] => img2.png +) + +Natural order sorting (case-insensitive) +Array +( + [0] => IMG0.png + [4] => img1.png + [3] => img2.png + [5] => IMG3.png + [2] => img10.png + [1] => 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>sort</function>, http://cvs.php.net/diff.php/phpdoc/en/reference/array/functions/natsort.xml?r1=1.8&r2=1.9&ty=u Index: phpdoc/en/reference/array/functions/natsort.xml diff -u phpdoc/en/reference/array/functions/natsort.xml:1.8 phpdoc/en/reference/array/functions/natsort.xml:1.9 --- phpdoc/en/reference/array/functions/natsort.xml:1.8 Sun Aug 17 08:21:03 2003 +++ phpdoc/en/reference/array/functions/natsort.xml Thu Feb 26 14:55:33 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.8 $ --> +<!-- $Revision: 1.9 $ --> <!-- splitted from ./en/functions/array.xml, last change in rev 1.25 --> <refentry id="function.natsort"> <refnamediv> @@ -16,10 +16,11 @@ </methodsynopsis> <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: + 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> @@ -70,12 +71,6 @@ </para> </example> </para> - <note> - <para> - If you're wanting to maintain index/value associations, consider - using <literal>uasort($arr, 'strnatcmp')</literal>. - </para> - </note> <para> See also <function>natcasesort</function>, <function>strnatcmp</function>, and

« previous php.doc (#969359253) next »