Home > Backend Development > PHP Tutorial > 数组内部的数据同值查询有关问题,

数组内部的数据同值查询有关问题,

WBOY
Release: 2016-06-13 10:23:09
Original
861 people have browsed it

数组内部的数据同值查询问题,求助!
现在有三个数组$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);<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template