您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php中使用什么内置函数可将对象转为数组

2024/8/8 19:52:45发布44次查看
在php中,可以使用内置函数get_object_vars()来将对象转为数组,该函数可返回由对象属性组成的关联数组,语法格式“get_object_vars(object)”。
本教程操作环境:windows7系统、php7.1版,dell g3电脑
在php中,可以使用内置函数get_object_vars()来将对象转为数组
get_object_vars()返回由对象属性组成的关联数组。
语法:
get_object_vars ( object $obj )
返回由 obj 指定的对象中定义的属性组成的关联数组。
示例:
<?phpclass point2d { var $x, $y; var $label; function point2d($x, $y) { $this->x = $x; $this->y = $y; } function setlabel($label) { $this->label = $label; } function getpoint() { return array("x" => $this->x, "y" => $this->y, "label" => $this->label); }}// "$label" is declared but not defined$p1 = new point2d(1.233, 3.445);print_r(get_object_vars($p1));$p1->setlabel("point #1");print_r(get_object_vars($p1));?>
输出:
array ( [x] => 1.233 [y] => 3.445 [label] => ) array ( [x] => 1.233 [y] => 3.445 [label] => point #1 )
推荐学习:《php视频教程》
以上就是php中使用什么内置函数可将对象转为数组的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product