PHP - Classes and Objects
Given this class:
class Book {
public $title;
public $author;
public function __construct($title, $author) {
$this->title = $title;
$this->author = $author;
}
}
// Create an array of books with titles and authors
$booksData = [
['1984', 'George Orwell'],
['Brave New World', 'Aldous Huxley'],
['Fahrenheit 451', 'Ray Bradbury']
];
// Fill this array with Book objects
$books = [];
foreach ($booksData as $data) {
// Fill here
}
Which line correctly creates and adds a new Book object to $books inside the loop?
