您的位置:首页 > 其它

类中属性返回形式(对象,关联数组,索引数组)

2014-06-20 21:59 741 查看
class A {

public $x, $y;

function __construct($x, $y) {

$this->x = $x;

$this->y = $y;

}

function get_value($arr = true) {

if($arr == 'arr') {

// 类中属性以关联数组形式转换返回

return get_object_vars($this);

}else if($arr == 'obj') {

//类中属性以对象形式返回

return $this;

}else {

// 类中属性以索引数组形式转换返回

return array_values(get_object_vars($this));

}

}

}

$aa = new A(100, 200);

$ok = $aa->get_value();

print_r($ok);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐