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

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

WBOY
WBOYOriginal
2016-06-13 12:12:581086Durchsuche

代码里面有 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 中了,本来就是在一起的
只不过第二段的可能会覆盖第一段的

Stellungnahme:
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