From:             [EMAIL PROTECTED]
Operating system: NT 4.0 SP6a
PHP version:      4.3.0
PHP Bug Type:     Arrays related
Bug description:  array_multisort() changes array keys unexpectedly given numeric 
strings as keys

<script language="php">

/*
        The following code produces an unexpected result from the
array_multisort()
        function.
        
        The indices of the arrays are are modified for the two entries
        in which the numeric value reaches the first position of the string
index.
        Granted, all of the indices are numerical, and therefore may be assigned
to
        and integer when converted; however, the expected replacement would be
the
        integer value of the string representation. (i.e. "150014" would become
150014)
        
        In actuality, the indices "150014" and "120011" are converted to 1 and 0
        respectively.  Therefore, the associative array is no longer associative
and
        the indices do not relate to the original arrays, even though the sort
order
        is correct and the two arrays still relate to each other.
*/

$Category = array       (
                        "000001" => "Personal, Master", "000002" => "Information, 
Gorean",
                        "000003" => "Information, Gorean", "000004" => "Books, 
Information",
                        "000005" => "Books, Information", "000006" => "Information, 
Gorean",
                        "000007" => "Information, Gorean", "000008" => "Books, 
Information",
                        "000009" => "Books, Information", "000010" => "Group, 
Offline",
                        "000011" => "Internet, Link Collection", "120011" => 
"Internet, Link
Exchange",
                "000013" => "Books, Discussion", "000014" => "Books, Discussion",
                "150014" => "Books, Discussion", "000015" => "Books, Discussion",
                "000016" => "Books, Discussion", "000017" => "Books, Discussion",
                "000018" => "Books, Discussion" );
$LinksStatus = array    (
                        "000001" => "APPROVED", "000002" => "APPROVED", "000003" =>
"APPROVED",
                "000004" => "APPROVED", "000005" => "APPROVED", "000006" =>
"APPROVED",
                "000007" => "APPROVED", "000008" => "APPROVED", "000009" =>
"APPROVED",
                "000010" => "APPROVED", "000011" => "APPROVED", "120011" =>
"APPROVED",
                "000013" => "APPROVED", "000014" => "BROKEN", "150014" => "BROKEN",
                "000015" => "APPROVED", "000016" => "BROKEN", "000017" => "BROKEN",
                "000018" => "BROKEN" );

        echo("<h3>Sorting these 2 arrays</h3>\n<pre>");
        print_r($Category);
        print_r($LinksStatus);
        echo("</pre>"); 
        
//      I DO NOT KNOW WHY THE FOLLOWING LINE REASSIGNS INDEXES OF THE ARRAY
!!!
        array_multisort (       $Category, SORT_STRING, SORT_ASC,
                                                $LinksStatus, SORT_STRING, SORT_DESC);

        echo("<h3>Results in changed indices in the arrays</h3>\n<pre>");
        print_r($Category);
        print_r($LinksStatus);
        echo("</pre>"); 

</script>
-- 
Edit bug report at http://bugs.php.net/?id=21788&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=21788&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=21788&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=21788&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=21788&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=21788&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=21788&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=21788&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=21788&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=21788&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=21788&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21788&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=21788&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=21788&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=21788&r=gnused

Reply via email to