執行 ❯
獲取您
自己的 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" }
物件轉換為關聯陣列,屬性名稱變為鍵,屬性值變為值。