php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34217 Requesting array_unique() function that works with multi-dimensional arrays.
Submitted: 2005-08-23 10:15 UTC Modified: 2018-03-10 17:15 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: nickj-phpbugs at nickj dot org Assigned: cmb (profile)
Status: Closed Package: Arrays related
PHP Version: 5CVS-2005-08-23 (snap) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nickj-phpbugs at nickj dot org
New email:
PHP Version: OS:

 

 [2005-08-23 10:15 UTC] nickj-phpbugs at nickj dot org
Description:
------------
Requesting array_unique() function to work correctly with multi-dimensional arrays (or a new function that does the same thing, so as to retain backwards compatibility) 

Script:
===================================================
<?php

$array = array (1 => array(1, 2, 3),
                2 => array(1, 2),
                3 => array(1, 3, 4),
                4 => array(1, 2),
                5 => array(1, 3, 4)
               );

$array = array_unique ($array);

print_r ($array);

?>
===================================================

Current actual output:
===================================================
ludo:~/tmp/php-5.1-dev/array_unique# ../../php5-200507102230/sapi/cli/php ./test.php 
Array
(
    [1] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

)
ludo:~/tmp/php-5.1-dev/array_unique# 
===================================================

Desired output:
===================================================
ludo:~/tmp/php-5.1-dev/array_unique# ../../php5-200507102230/sapi/cli/php ./test.php 
Array
(
    [1] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

    [4] => Array
        (
            [0] => 1
            [1] => 2
        )

    [5] => Array
        (
            [0] => 1
            [1] => 3
            [2] => 4
        )

)
ludo:~/tmp/php-5.1-dev/array_unique# 
===================================================

Note the order of the keys isn't a big concern to me, although others may be concerned about this.

Various bogus bugs that people have logged when the encountering this behaviour:
Bug #16715, Bug #12690, Bug #13403, Bug #10891, Bug #12789, Bug #12528

I couldn't see a feature request for this though, so that's what this is.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-04 16:10 UTC] cz dot paranoiq at gmail dot com
this is still relevant for PHP 5.6 and PHP 7

i would call this rather a bug than a feature request. the actual result returned is a total nonsense and PHP generates a "Notice: Array to string conversion" for every item of array

it should be either fixed or throw something stronger than a notice

related bug: https://bugs.php.net/bug.php?id=62977
 [2016-12-30 23:01 UTC] cmb@php.net
-Package: Feature/Change Request +Package: Arrays related
 [2018-03-10 17:15 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2018-03-10 17:15 UTC] cmb@php.net
> this is still relevant for PHP 5.6 and PHP 7

No, because as of PHP 5.2.9 the $sort_flags parameter has been
added, which allows to do a SORT_REGULAR with the requested
behavior, see <https://3v4l.org/tPZWv>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 01:01:28 2024 UTC