运行 ❯
获取您自己的
PHP
服务器
×
更改方向
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <pre> <?php class Car { public $color; public $model; public function __construct($color, $model) { $this->color = $color; $this->model = $model; } public function message() { return "My car is a " . $this->color . " " . $this->model . "!"; } } $myCar = new Car("red", "Volvo"); $myCar = (array) $myCar; var_dump($myCar);?> </pre> <p>Objects converts into associative arrays where the property names becomes the keys and the property values becomes the values.</p> </body> </html>
array(2) { ["color"]=> string(3) "red" ["model"]=> string(5) "Volvo" }
对象转换为关联数组,其中属性名称变为键,属性值变为值。