时间:2021-07-01 10:21:17 帮助过:18人阅读
b = 1;$a['b'] = 2;echo $a->b;echo $a['b'];
要写个方法实现。
class a{ public $aaa=1; function fetch($type){ if($type=='assoc'){ $ret = new stdClass(); $ret->aaa = $this->aaa; }elseif($type=='array'){ $ret = array(); $ret['aaa'] = $this->aaa; } return $ret; }}$d = new a();$obj = $d->fetch('assoc');var_dump($obj);$arr = $d->fetch('array');var_dump($arr);
object(stdClass)[2] public 'aaa' => int 1array (size=1) 'aaa' => int 1