数组内部的数据同值查询问题,求助!
现在有三个数组$data1=array( '1,2,3,4,5,6 ', '1,2,3,4,5,7 ', '1,2,3,4,5,8 ', '1,2,3,4,5,9 ');
$data2=array(1,3,5,7,11,13,15,17,19,21);
$data3=array(3,6,9,12,15,18,21,24);
同时数组$data1已经在数据库hmk中存在
格式如下:
l1 l2 l3 l4 l5 l6
1 2 3 4 5 6
1 2 3 4 5 7....
现在我想在HMK中增加字段 data2 data3,用来存储每一条记录在$data2,$data3中出现的次数.有什么好的方法么?
应该在数组内操作然后将结果存储到数据库,还是在数据库内直接操作啊?请大侠帮忙啊!~~谢谢!
------解决方案--------------------
PHP code
<?php
$data1=array('1,2,3,4,5,6', '1,2,3,4,5,7','1,2,3,4,5,8','1,2,3,4,5,9');
$data2=array(1,3,5,7,11,13,15,17,19,21);
$data3=array(3,6,9,12,15,18,21,24);
foreach ($data1 as $key=>$value) {
$data1[$key].=','.count(array_intersect(explode(',',$value),$data2));
$data1[$key].=','.count(array_intersect(explode(',',$value),$data3));
}
print_r($data1);