代码里面有 oneline 的数据和 twoline 的数据,如何把这两组数据并集起来?

WBOY
發布: 2016-06-23 13:42:24
原創
1038 人瀏覽過

	public function line($config,$qq='',$data=array()){		$array = array();		$line = $config['line'];		$url = trim($config[$line]);		if($line == 'oneline' && $qq != ''){			$content = $this->proGetCont($url.'/index.php?m=account&c=index&a=search&q='.$qq);			preg_match_all('/<tr>([\s\S]*?)<\/tr>/i',$content,$pregArray);			if(count($pregArray)){				foreach($pregArray[0] as $value){					preg_match_all('/<td([\s\S]*?)<\/td>/i',$value,$v); 					$ipVal = $this->strSub($v[0][3],'fa">','</td>');					$ipid = M('iplib')->where('ipval = \''.$ipVal.'\'')->find()['id'];					if(!$ipid){						$ipid = M('iplib')->add(array('ipval'=>$ipVal,'namelist'=>'1'));					}					$timsInt = strtotime($this->strSub($v[0][4],'fa">','</td>'));					$boolTure=true;					foreach($data as $d){						if(($d['jbtime'] == $timsInt) && ($ipid == $d['jbip'])){							$boolTure = false;						}					}					if($boolTure || count($data) ==0){						$array[] = array(								'jbip'=>$ipid,								'jbtime'=>$timsInt,								'number'=>$qq,								'class'=>'1',								'type'=>'4',								'whitelist'=>'0'							);					}									}				$rel = M('number')->addAll($array);			}				}				if($line == 'twoline' ){			$number = '';			$class = '1';			if($qq != ''){				if(!is_numeric($qq) || (strlen($qq) < 5) || (strlen($qq) > 13) ){					$this->error('您查询的QQ号格式错误!');					return $data;				}				$content = $this->proGetCont($url.'/form.php','qq='.$qq);				$number = $qq;							}			if($content){							$type = M('type')->select();				$typeArray = array();				foreach($type as $v){					$typeArray[trim($v['name'])] = $v['id'];				}									preg_match_all('/{([\s\S]*?)}/i',$content,$pregArray);					if(count($pregArray)){						foreach($pregArray[0] as $k => $value){							$ipVal = $this->strSub($value,'myip":',',"date');							$ipVal = str_replace('"','',$ipVal);							$ipid = M('iplib')->where('ipval = \''.$ipVal.'\'')->find()['id'];							if(!$ipid){								$ipid = M('iplib')->add(array('ipval'=>$ipVal,'namelist'=>'1'));							}							$timsInt = strtotime($this->strSub($value,'date":"','","typetext'));							$boolTure=true;							foreach($data as $d){								if(($d['jbtime'] == $timsInt) && ($ipid == $d['jbip'])){									$boolTure = false;								}							}							if($boolTure || count($data) ==0){								$array[$k]['jbip'] = $ipid;								$array[$k]['jbtime'] = $timsInt;								if($class == '1'){									$type = trim($this->unicode_decode($this->strSub($value,'typetext":"','","qq1')));								}								if($class == '2'){									$type = trim($this->unicode_decode($this->strSub($value,'typetext":"','","ww1')));								}								$array[$k]['type'] = (array_key_exists($type,$typeArray))?$typeArray[$type]:'其他';								$array[$k]['number'] = $number;								$array[$k]['class'] = $class;								$array[$k]['whitelist'] = '0';							}						}						$rel = M('number')->addAll($array);					}				}			}		}						if(count($array)){			foreach($array as $a){				$data[]=$a;			}		}				return $data;	}
登入後複製

代码里面有 oneline 的数据和 twoline 的数据,如何把这两组数据并集起来,谢谢!


回复讨论(解决方案)

<?php                                        //  $a = 1 2 3 4    $union =                            //  $b =   2   4 5 6        array_merge(            array_intersect($a, $b),    //         2   4            array_diff($a, $b),         //       1   3            array_diff($b, $a)          //               5 6        );                              //  $u = 1 2 3 4 5 6?>
登入後複製

两段的数据都写到 $array 中了,本来就是在一起的
只不过第二段的可能会覆盖第一段的

我先试试,多谢两位。

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板