要在PHP中创建对象的副本,代码如下-
输出结果
这将产生以下输出-
JackKevin TomRyan现在让我们来看另一个示例-
<?php class Demo { public $deptname; public $deptzone; public function __construct($a, $b) { $this->deptname = $a; $this->deptzone = $b; } } $val = new Demo(Finance, West); $copy = clone $val; print_r($val); print_r($copy); ?>输出结果
这将产生以下输出-
Demo Object( [deptname] => Finance [deptzone] => West ) Demo Object( [deptname] => Finance [deptzone] => West )