Home  >  Article  >  Backend Development  >  PHP array 中累加实体类的实体

PHP array 中累加实体类的实体

WBOY
WBOYOriginal
2016-06-13 12:06:001153browse

PHP array 中追加实体类的实体

本帖最后由 xuzuning 于 2014-09-01 10:34:42 编辑
function getqos_one($ethnumber)<br />	{<br />		$qos = new qosclass();<br />		$file="/usr/local/lte/em100cfg".$ethnumber;<br />		echo $file;<br />		$content=file_get_contents($file);<br />		$list=explode("\n",$content);<br />		$qosarry=array();<br />		for($i=1;$i<5;$i++)<br />		{<br />		foreach($list as $line)<br />		{<br />			$line=trim($line);<br />			$eq=strpos($line,'=');<br /><br />			if($eq>0)//该行存在‘=’号<br />				$val=substr($line,$eq+1);<br />			<br />			if(strpos($line,"qos".$i."_en")===0)<br />			{<br />				$qos->qos=$val;//连接状态<br />			}<br />			else if(strpos($line,"qos".$i."_cid")===0)<br />			{<br />				$qos->qos_cid=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_packet_filter_identifier")===0)<br />			{<br />				$qos->qos_packet_filter_identifier=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_evaluation_precedence_index")===0)<br />			{<br />				$qos->qos_evaluation_precedence_index=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_source_address")===0)<br />			{<br />				$qos->qos_source_address=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_subnet_mask")===0)<br />			{<br />				$qos->qos_subnet_mask=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_protocol_number")===0)<br />			{<br />				$qos->qos_protocol_number=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_destination_port_range")===0)<br />			{<br />				$qos->qos_destination_port_range=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_source_port_range")===0)<br />			{<br />				$qos->qos_source_port_range=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_direction")===0)<br />			{<br />				$qos->qos_direction=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_QCI")===0)<br />			{<br />				$qos->qos_QCI=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_DL_GBR")===0)<br />			{<br />				$qos->qos_DL_GBR=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_UL_GBR")===0)<br />			{<br />				$qos->qos_UL_GBR=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_DL_MBR")===0)<br />			{<br />				$qos->qos_DL_MBR=$val;<br />			}<br />			else if(strpos($line,"qos".$i."_UL_MBR")===0)<br />			{<br />				$qos->qos_UL_MBR=$val;<br />			}<br />			<br />		}<br />		//print_r($qos);//这里打印每一个qos都是正常的<br />		array_unshift($qosarry,$qos);<br />		//print_r($qosarry);//这里打印qosarry里面的值 就全是空的了 注:$i=3或者4时 qos的值都是空<br />		}<br />		print_r($qosarry);<br />		return $qosarry;<br /><br />class qosclass<br />	{<br /><br />		public $qos;//使能<br /><br />		public $qos_cid;<br /><br />		public $qos_packet_filter_identifier;<br /><br />		public $qos_evaluation_precedence_index;<br /><br />		public $qos_source_address;<br /><br />		public $qos_subnet_mask;<br /><br />		public $qos_protocol_number;<br /><br />		public $qos_destination_port_range;<br /><br />		public $qos_source_port_range;<br /><br />		public $qos_direction;<br /><br />		public $qos_QCI;<br /><br />		public $qos_DL_GBR;<br /><br />		public $qos_UL_GBR;<br /><br />		public $qos1_DL_MBR;<br /><br />		public $qos_UL_MBR;<br /><br /><br />	}<br />

为何在unshift之后 值就没了呢?还是第四个的值取代了前面几个的值?
------解决方案--------------------
这不就对了吗?
数据中 gos3_xxxx、gos4_xxxx 都是空的
所以 $qosarry 中也就空了

把 array_unshift($qosarry,$qos);
改成 array_unshift($qosarry, clone $qos);
就正确了
Statement:
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
Previous article:PHP中模糊查询解决方案Next article:php 循环异常