Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.6.0a3

Bug #6293 array_intersect_key produces incorrect results with more than 2 arguments
Submitted: 2005-12-19 23:20 UTC
From: court at idstrom dot com Assigned: arpad
Status: Closed Package: PHP_Compat
PHP Version: 5.0.5 OS: Mac OSX 10.4.3
Roadmaps: 1.6.0a1    
Subscription  
Comments Add Comment Add patch


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 : 47 + 22 = ?

 
 [2005-12-19 23:20 UTC] court at idstrom dot com
Description: ------------ PHP_Compat version 1.5 Test script: --------------- <? require_once('PHP/Compat/Function/array_intersect_key.php'); print_r(array_intersect_key( array('a'=>1, 'b'=>2, 'c'=>3, 'd'=>4), array('a'=>0, 'c'=>0), array('a'=>0, 'd'=>4) )); ?> Here's a correct (and slightly faster) implementation that requires php 4 >= 4.0.4 (for call_user_func_array) function array_intersect_key() { $args = func_get_args(); $arg_keys = array_map('array_keys', $args); $result_keys = call_user_func_array('array_intersect', $arg_keys); $first_arg = $args[0]; $result = array(); foreach($result_keys as $key) { $result[$key] = $first_arg[$key]; } return $result; } } Expected result: ---------------- Array ( [a] => 1 ) Actual result: -------------- Array ( [a] => 1 [c] => 3 [d] => 4 )

Comments

 [2005-12-29 10:00 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!