ID:               21788
 User updated by:  [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
 Status:           Open
 Bug Type:         Arrays related
 Operating System: NT 4.0 SP6a
 PHP Version:      4.3.0
 New Comment:

<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 an 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>


Previous Comments:
------------------------------------------------------------------------

[2003-01-20 21:58:09] [EMAIL PROTECTED]

<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 this bug report at http://bugs.php.net/?id=21788&edit=1

Reply via email to