时间:2021-07-01 10:21:17 帮助过:14人阅读
class so_getMaterialType
{
var $CreateTime = '';
var $IsDefault = '';
var $UpdateTime = '';
}
$p = array();
$sql = 'SELECT * from tb where lid<50';
$re_materialTypeID = $db->getAll($sql);
foreach($re_materialTypeID as $key => $val)
{
$getMaterialType = new so_getMaterialType ; //为什么每次循环都要新申请一遍,而不是放在循环外面申请一次即可??
$getMaterialType->CreateTime = $val['CreateTime'];
$getMaterialType->IsDefault = $val['IsDefault'];
$getMaterialType->UpdateTime = $val['UpdateTime'] ;
$p[] = $getMaterialType ;
}
var_dump($p);
return $p;
/*————————这种写法与上面差别是什么??———————————*/
$getMaterialType = array();
$getMaterialType[] = new so_getMaterialType ;
$sql = 'SELECT * from tb where lid<50';
$re_materialTypeID = $db->getAll($sql);
foreach($re_materialTypeID as $key => $val)
{
$getMaterialType[$key]->CreateTime = $val['CreateTime'];
$getMaterialType[$key]->IsDefault = $val['IsDefault'];
$getMaterialType[$key]->UpdateTime = $val['UpdateTime'] ;
}
var_dump($getMaterialType);
return $getMaterialType;
class so_getMaterialType {
var $CreateTime = '';
var $IsDefault = '';
var $UpdateTime = '';
function __construct($a) {
foreach($a as $k->$v) $this->$k = $v;
}
}
$p = array();
$sql = 'SELECT * from tb where lid<50';
$re_materialTypeID = $db->getAll($sql);
foreach($re_materialTypeID as $key => $val) {
$p[] = new so_getMaterialType($val) ;
}
$getMaterialType = new so_getMaterialType ;
$p[] = $getMaterialType ;