>  기사  >  백엔드 개발  >  代码里面有 oneline 的数据和 twoline 的数据,怎么把这两组数据并集起来

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

WBOY
WBOY원래의
2016-06-13 12:12:581061검색

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

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

代码里面有 oneline 的数据和 twoline 的数据,如何把这两组数据并集起来,谢谢!
------解决思路----------------------
<br /><?php<br />                                        //  $a = 1 2 3 4<br />    $union =                            //  $b =   2   4 5 6<br />        array_merge(<br />            array_intersect($a, $b),    //         2   4<br />            array_diff($a, $b),         //       1   3<br />            array_diff($b, $a)          //               5 6<br />        );                              //  $u = 1 2 3 4 5 6<br />?><br />

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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.