php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30082 Multidimensional arrays copy or array_multisort bug
Submitted: 2004-09-14 10:39 UTC Modified: 2005-07-18 09:49 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: techtonik@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS, 4CVS (2005-06-19) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
46 + 18 = ?
Subscribe to this entry?

 
 [2004-09-14 10:39 UTC] techtonik@php.net
Description:
------------
Seems, that multidimensional arrays are copied with one dimension, which contains references to other included arrays.

I haven't found any references in manual, so this must be a bug. 

Reproduce code:
---------------
<?php

$a[0]['id']    = array(22, 12, 33, 55);
$a[0]['secid'] = array("a","b","c","d");

print_r($a);

$b = $a;

foreach ($b as $k => $v) {
    array_multisort($v['id'], SORT_DESC, $v['secid'], SORT_DESC);
}

print_r($a);
?>

Expected result:
----------------
Array
(
    [0] => Array
        (
            [id] => Array
                (
                    [0] => 22
                    [1] => 12
                    [2] => 33
                    [3] => 55
                )

            [secid] => Array
                (
                    [0] => a
                    [1] => b
                    [2] => c
                    [3] => d
                )
        )
)
Array
(
    [0] => Array
        (
            [id] => Array
                (
                    [0] => 22
                    [1] => 12
                    [2] => 33
                    [3] => 55
                )

            [secid] => Array
                (
                    [0] => a
                    [1] => b
                    [2] => c
                    [3] => d
                )
        )
)


Actual result:
--------------
Array
(
    [0] => Array
        (
            [id] => Array
                (
                    [0] => 22
                    [1] => 12
                    [2] => 33
                    [3] => 55
                )

            [secid] => Array
                (
                    [0] => a
                    [1] => b
                    [2] => c
                    [3] => d
                )
        )
)
Array
(
    [0] => Array
        (
            [id] => Array
                (
                    [0] => 55
                    [1] => 33
                    [2] => 22
                    [3] => 12
                )

            [secid] => Array
                (
                    [0] => d
                    [1] => c
                    [2] => a
                    [3] => b
                )
        )
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-02 16:29 UTC] sniper@php.net
See also bug #30076
 [2005-07-18 09:49 UTC] dmitry@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #25359 (same reason: reference)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 18:01:32 2024 UTC