|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-02-04 00:41 UTC] ejrx7753 at gmail dot com
Description: ------------ A section of "ext/standard/tests/array/sort_basic.phpt" with case insensitive natural sort does not give the expected result. Tested on OS X Sierra PHP 7.0.13, PHP 7.1.0, and "PHP 7.0.13-0ubuntu0.16.04.1" The test expects [6]=> string(7) "Orange3" [7]=> string(8) "orange20" But it gives string(8) "orange20" [7]=> string(7) "Orange3" Obivously expecting "3" before "20" in nat sort. Note also that the sort_basic does not properly test the insensitive case (as there are no exeptional elements with case considered) so that was not tested and assumed also to be not working. Test script: --------------- <?php // associative array containing unsorted string values $unsorted_strings = array( "l" => "lemon", "o" => "orange", "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", "b" => "banana", ); echo "\n-- Testing sort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; $temp_array = $unsorted_strings; sort($temp_array, SORT_NATURAL|SORT_FLAG_CASE); var_dump( $temp_array); Expected result: ---------------- [6]=> string(7) "Orange3" [7]=> string(8) "orange20" Actual result: -------------- string(8) "orange20" [7]=> string(7) "Orange3" PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 08:00:02 2025 UTC |
I just tested the underlying sort function and also get a failure to compare in natural order. var_dump(strnatcasecmp("orange20","Orange3")); var_dump(strnatcmp("orange20","orange3")); var_dump(strcmp("1","2")); Outputs int(1) int(1) int(-1) Expected -1 -1 -1