php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27317 array_unique weirdness
Submitted: 2004-02-19 02:28 UTC Modified: 2004-02-24 17:13 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Jan at Bytesmiths dot com Assigned:
Status: No Feedback Package: Arrays related
PHP Version: 4.3.4 OS: MacOS X 10.3
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Jan at Bytesmiths dot com
New email:
PHP Version: OS:

 

 [2004-02-19 02:28 UTC] Jan at Bytesmiths dot com
Description:
------------
array_unique seems to be losing a value somehow when two 
arrays are merged that contain the same value. I am 
merging two arrays, then feeding the result to 
array_unique. (What I REALLY want is a set!) print_r 
seems to show a proper result. However, waling through 
the array results in an empty value. In this 
case, 'IsNew' is missing. I changed the order of the 
merge, and a DIFFERENT value was missing!

If merging the two arrays results in a set (no 
duplicates), then array_unique seems to work fine.

Reproduce code:
---------------
// $InfoThumb AND $PopupThumb determine what fields to fetch. Build the proper query string.
$fieldNames = array_unique(array_merge($PopupThumb, $InfoThumb));
print_r($PopupThumb);
print_r($InfoThumb);
print_r($fieldNames);
for($i=0; $i<count($fieldNames); $i++)
	$fields .= ', ' . $fieldNames[$i];

$inc = $NumberOfColumns * $NumberOfRows;
$sql = "SELECT ID, ImageThumb, ToShow $fields FROM Gallery" . $sql_filter . $sql_sort;
if($total >= $inc) $sql .= " LIMIT $start, $inc";

die($sql);

Expected result:
----------------
SELECT ID, ImageThumb, ToShow , 
Title, Price, IsNew, Medium, Width, Height, Depth FROM 
Gallery WHERE ToShow=1 ORDER BY Updated DESC LIMIT 0, 10

Actual result:
--------------
Array (  [0] => Title  [1] => Price ) Array (  [0] => 
Title  [1] => Medium  [2] => Width  [3] => Height  [4] 
=> Depth  [5] => IsNew ) Array (  [0] => Title  [1] => 
Price  [3] => Medium  [4] => Width  [5] => Height  [6] 
=> Depth  [7] => IsNew ) SELECT ID, ImageThumb, ToShow , 
Title, Price, , Medium, Width, Height, Depth FROM 
Gallery WHERE ToShow=1 ORDER BY Updated DESC LIMIT 0, 10

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-19 02:45 UTC] helly@php.net
Please provide a short reproducing script that does not require any database or precondiftions like the page generating your queries or provide your query string and the way it is parsed to the variables - but only if that is really neccessary.
 [2004-02-24 17:13 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2004-12-17 15:01 UTC] arve at coretrek dot no
I am experiencing the exact same problem as described in the original description. 
OS/server is FreeBSD 4.10-RELEASE-p4 and Apache version is Apache/1.3.33 (Unix) mod_ssl/2.8.22 OpenSSL/0.9.7d PHP/4.3.10. The same problem exists on 4.3.9 as well.
I have tried to write a simple test case, but when doing that,  I am not able to reproduce this behaviour. The system where this bug appears is to complex for me to try narrow it down to the exact reproducing code. 

Arve Skj?restad
Senior developer
CoreTrek AS
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 12 07:01:28 2024 UTC