php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10891 array_unique does not work properly anymore
Submitted: 2001-05-16 03:28 UTC Modified: 2001-09-14 19:42 UTC
From: kost at itc-ua dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.0.5 OS: UNIX FreeBSD 4.1.1
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:
45 + 4 = ?
Subscribe to this entry?

 
 [2001-05-16 03:28 UTC] kost at itc-ua dot com
I've installed php 4.0.5 and function "array_unique" does not work correctly anymore.
The following code works with 4.0.3pl1 as it's supposed to do:
<?
$arr[0][] = 1;
$arr[0][] = 2;
$arr[0][] = 3;

$arr[1][] = 1;
$arr[1][] = 2;
$arr[1][] = 3;

$arr[2][] = 1;
$arr[2][] = 2;
$arr[2][] = 5;

$arr = array_unique($arr);

while(list(,$n) = each($arr)) echo implode(',',$n)."<br>";

?>
Output is :
1,2,3
1,2,5

But with php 4.0.5 it refuses to work and returns : 1,2,3

I've looked through source code "ext/standard/array.c" and revealed some differences between 4.0.3 - 4.0.5:

> set_compare_func(SORT_STRING); - 4.0.5
> set_compare_func(SORT_REGULAR); - 4.0.3

Some others functions array_*  also use SORT_STRING comparing instead of SORT_REGULAR

Best regards,
Konstantin,
http://itc-ua.com

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-14 19:38 UTC] jeroen@php.net
Array_unique isn't supposed to handle multi-dimension strings, nor objects.

See also 10658
 [2001-09-14 19:42 UTC] jeroen@php.net
Err: Array_unique/array_diff/array_intersect isn't supposed to handle multi-dimension _arrays_, nor objects.

See also 10658


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 08:01:28 2024 UTC