首页 > 其他 > 详细

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

时间:2014-06-22 23:19:27      阅读:423      评论:0      收藏:0      [点我收藏+]

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);

类中属性返回形式(对象,关联数组,索引数组),布布扣,bubuko.com

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

原文:http://www.cnblogs.com/lin3615/p/3800199.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!