How can I loop through a PHP array of objects (the objects are books with title and price) and output the one whose title comes after the letter R alphabetically? Thanks
Should I create an array with alphabetic letters then merge that array with book's array (in this case bookInformation)?
class Book {
public $title;
public $price;
public function __construct($title, $price) {
$this->title = $title;
$this->price = $price;
}
public function info() {
echo $this->title . ' is ' . $this->price . '<br>';
}
}
$bookOne = new Book("Mall", 13.95);
$bookTwo = new Book("Will", 23.99);
$bookOne->info();
$bookTwo->info();
$bookInformation = [$bookOne, $bookTwo];