Heim > Backend-Entwicklung > PHP-Tutorial > 代码里面有 oneline 的数据和 twoline 的数据,如何把这两组数据并集起来?

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

WBOY
Freigeben: 2016-06-23 13:42:24
Original
1046 Leute haben es durchsucht

	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;	}
Nach dem Login kopieren

代码里面有 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?>
Nach dem Login kopieren

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

我先试试,多谢两位。

Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage