php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41324 array_unique problem
Submitted: 2007-05-08 08:43 UTC Modified: 2007-05-08 11:43 UTC
From: kami dot fubuki at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.2 OS: windows xp
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kami dot fubuki at gmail dot com
New email:
PHP Version: OS:

 

 [2007-05-08 08:43 UTC] kami dot fubuki at gmail dot com
Description:
------------
array_unique doesn't seem to work correctly.

Reproduce code:
---------------
print_r($unique_terms);
$unique_terms=array_unique($unique_terms);
print_r($unique_terms);exit;

Expected result:
----------------
Array
(
    [0] => a
    [1] => c
    [2] => d
    [3] => b
    [4] => c
    [5] => b
    [6] => c
    [7] => d
    [8] => b
    [9] => c
    [10] => d
)
Array
(
    [0] => a
    [1] => c
    [2] => d
    [3] => b
)

Actual result:
--------------
Array
(
    [0] => a
    [1] => c
    [2] => d
    [3] => b
    [4] => c
    [5] => b
    [6] => c
    [7] => d
    [8] => b
    [9] => c
    [10] => d
)
Array
(
    [0] => a
    [1] => c
    [2] => d
    [3] => b
    [4] => c
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-08 09:16 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2007-05-08 09:19 UTC] judas dot iscariote at gmail dot com
works for me..

<?php

$unique_terms = array('a', 'c', 'd', 'b', 'c', 'b', 'c', 'd', 'b', 'c', 'd');

print_r($unique_terms);
$unique_terms= array_unique($unique_terms);
print_r($unique_terms);exit;

Array
(
    [0] => a
    [1] => c
    [2] => d
    [3] => b
    [4] => c
    [5] => b
    [6] => c
    [7] => d
    [8] => b
    [9] => c
    [10] => d
)
Array
(
    [0] => a
    [1] => c
    [2] => d
    [3] => b
)

are you using any kind of zend_extension ? are you sure the "conflicting 'c'" does not have spaces or other chars inside ?
 [2007-05-08 11:30 UTC] kami dot fubuki at gmail dot com
Thanks!
I've dumped the variables (var_dump();) and it seems that there was a trailing newline (because of fscanf) from the windows vs *nix formatting. It seems that print_r didn't append this newline character into the formatting.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Aug 15 18:00:02 2025 UTC