|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-06-08 08:02 UTC] alex at emailclick dot com
Description:
------------
There is a strange behaviour when I try to check the intersection between two array (of keys (of filtered by callback arrays)).
The result of that operation is saved in an array which contains the value at index 0 when the cycle is odd (1,3,5...). Instead the value will be saved at index 1 when the cycle is pair (2,4,6...).
Reproduce code:
---------------
foreach($dates as $date){
foreach($machines as $model){
if(!is_array($models[$model])) models[$model]=array();
$id=array_intersect( array_keys(array_filter($data->data['udate'],create_function('$date','return $date=="'.$date.'";'))),array_keys(array_filter($data->data['model'],create_function('$model','return $model=="'.$model.'";'))));
var_dump($id);echo '<br />';
}
}
Expected result:
----------------
array(1) { [0]=> int(0) }
array(1) { [0]=> int(1) }
array(1) { [0]=> int(2) }
array(1) { [0]=> int(3) }
Actual result:
--------------
array(1) { [0]=> int(0) }
array(1) { [1]=> int(1) }
array(1) { [0]=> int(2) }
array(1) { [1]=> int(3) }
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Mar 18 23:00:01 2026 UTC |
This code can generate the "bug". <?php $dates=array("2009-06-09 16:27:00","2009-06-10 15:04:54"); $machines=array("A","B","C"); $data['udate']=array("2009-06-09 16:27:00","2009-06-09 16:27:00","2009-06-09 16:27:00","2009-06-10 15:04:54","2009-06-10 15:04:54","2009-06-10 15:04:54"); $data['model']=array("A","B","C","A","B","C"); $models=array(); foreach($dates as $date){ foreach($machines as $model){ if(!is_array($models[$model])) $models[$model]=array(); $id=array_intersect( array_keys(array_filter($data['udate'],create_function('$date','return$date=="'.$date.'";'))), array_keys(array_filter($data['model'],create_function('$model','return $model=="'.$model.'";'))) ); var_dump($id);echo '<br />'; } } ?>