本文主要是介绍php get_object_vars()函数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
get_object_vars :返回由对象属性组成的关联数组
For example:
class Point2D{
public $x,$y;
public $label;
public function __construct($x,$y){
$this->x=$x;
$this->y=$y;
}
public function setLabel($label){
$this->label=$label;
}
public function getPoint(){
return array('x'=>$this->x,'y'=>$this->y,'label'=>$this->label);
}
}
$p1=new Point2D('1.2333','3.445');
print_r(get_object_vars($p1));
$p1->setLabel("point#1");
print_r(get_object_vars($p1));
返回结果:
Array ( [x] => 1.2333 [y] => 3.445 [label] => ) Array ( [x] => 1.2333 [y] => 3.445 [label] => point#1 )
这篇关于php get_object_vars()函数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!