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

相关文章:

  • 2021-06-14
  • 2022-12-23
  • 2021-10-10
  • 2022-02-22
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-05-02
猜你喜欢
  • 2022-12-23
  • 2021-05-19
  • 2021-04-29
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2022-02-26
相关资源
相似解决方案