当前位置:Gxlcms > PHP教程 > PHParray中累加实体类的实体

PHParray中累加实体类的实体

时间:2021-07-01 10:21:17 帮助过:33人阅读

PHP array 中追加实体类的实体
本帖最后由 xuzuning 于 2014-09-01 10:34:42 编辑

function getqos_one($ethnumber)
{
$qos = new qosclass();
$file="/usr/local/lte/em100cfg".$ethnumber;
echo $file;
$content=file_get_contents($file);
$list=explode("\n",$content);
$qosarry=array();
for($i=1;$i<5;$i++)
{
foreach($list as $line)
{
$line=trim($line);
$eq=strpos($line,'=');

if($eq>0)//该行存在‘=’号
$val=substr($line,$eq+1);

if(strpos($line,"qos".$i."_en")===0)
{
$qos->qos=$val;//连接状态
}
else if(strpos($line,"qos".$i."_cid")===0)
{
$qos->qos_cid=$val;
}
else if(strpos($line,"qos".$i."_packet_filter_identifier")===0)
{
$qos->qos_packet_filter_identifier=$val;
}
else if(strpos($line,"qos".$i."_evaluation_precedence_index")===0)
{
$qos->qos_evaluation_precedence_index=$val;
}
else if(strpos($line,"qos".$i."_source_address")===0)
{
$qos->qos_source_address=$val;
}
else if(strpos($line,"qos".$i."_subnet_mask")===0)
{
$qos->qos_subnet_mask=$val;
}
else if(strpos($line,"qos".$i."_protocol_number")===0)
{
$qos->qos_protocol_number=$val;
}
else if(strpos($line,"qos".$i."_destination_port_range")===0)
{
$qos->qos_destination_port_range=$val;
}
else if(strpos($line,"qos".$i."_source_port_range")===0)
{
$qos->qos_source_port_range=$val;
}
else if(strpos($line,"qos".$i."_direction")===0)
{
$qos->qos_direction=$val;
}
else if(strpos($line,"qos".$i."_QCI")===0)
{
$qos->qos_QCI=$val;
}
else if(strpos($line,"qos".$i."_DL_GBR")===0)
{
$qos->qos_DL_GBR=$val;
}
else if(strpos($line,"qos".$i."_UL_GBR")===0)
{
$qos->qos_UL_GBR=$val;
}
else if(strpos($line,"qos".$i."_DL_MBR")===0)
{
$qos->qos_DL_MBR=$val;
}
else if(strpos($line,"qos".$i."_UL_MBR")===0)
{
$qos->qos_UL_MBR=$val;
}

}
//print_r($qos);//这里打印每一个qos都是正常的
array_unshift($qosarry,$qos);
//print_r($qosarry);//这里打印qosarry里面的值 就全是空的了 注:$i=3或者4时 qos的值都是空
}
print_r($qosarry);
return $qosarry;

class qosclass
{

public $qos;//使能

public $qos_cid;

public $qos_packet_filter_identifier;

public $qos_evaluation_precedence_index;

public $qos_source_address;

public $qos_subnet_mask;

public $qos_protocol_number;

public $qos_destination_port_range;

public $qos_source_port_range;

public $qos_direction;

public $qos_QCI;

public $qos_DL_GBR;

public $qos_UL_GBR;

public $qos1_DL_MBR;

public $qos_UL_MBR;


}

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

把 array_unshift($qosarry,$qos);
改成 array_unshift($qosarry, clone $qos);
就正确了

人气教程排行