How can multiple objects of a class be instantiated in PHP?
To instantiate multiple objects of a class in PHP, you can simply create new instances of the class using the `new` keyword multiple times. Each new instance will be a separate object with its own set of properties and methods.
class MyClass {
public $name;
public function __construct($name) {
$this->name = $name;
}
}
// Instantiate multiple objects of MyClass
$object1 = new MyClass('Object 1');
$object2 = new MyClass('Object 2');
$object3 = new MyClass('Object 3');
Related questions
-
PHP functions form outputs structured manner
-
Imagettftext center multi-line text
-
file search folder search optimization