这是一个相当容易的问题,但我似乎找不到合适的答案.
假设我在actionScript 3中写了这样一个对象:
var myCar = new Object(); myCar.engine = "Nice Engine"; myCar.numberOfDoors = 4; myCar.howFast= 150;
我如何用PHP编写这样的东西?
$myCar = new stdClass; $myCar->engine = 'Nice Engine'; $myCar->numberOfDoors = 4; $myCar->howFast = 150;
查看对象的文档以进行更深入的讨论.
您可以使用类,例如:
class Car { public $engine; public $numberOfDoors; public $howFast; } $myCar = new Car(); $myCar->engine = 'Nice Engine'; $myCar->numberOfDoors = 4; $myCar->howFast = 150;
或者如果您只需要此对象用于属性存储,则可以使用关联数组,如:
$myCar['engine'] = "Nice engine"; $myCar['numberOfDoors'] = 4; $myCar['howFast'] = 150;