From:             Jan at Bytesmiths dot com
Operating system: MacOS X 10.3
PHP version:      4.3.4
PHP Bug Type:     Arrays related
Bug description:  array_unique weirdness

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

-- 
Edit bug report at http://bugs.php.net/?id=27317&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27317&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27317&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27317&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27317&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27317&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27317&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27317&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27317&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27317&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27317&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27317&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27317&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27317&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27317&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27317&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27317&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27317&r=float

Reply via email to