У меня есть объекты в массиве. Я хочу получить доступ к свойствам этих объектов, но мне не повезло.PHP: не удается получить доступ к ключу объекта в массиве
class Article {
public $category;
public $title;
public $img;
public $location;
public $text;
public function __construct($category, $title, $img, $location, $text) {
$this->category = $category;
$this->title = $title;
$this->img = $img;
$this->location = "pages/" . $location;
$this->text = $text;
}
}
//db of articles
$runawayFive = new Article("news", "The Runaway Five Comes to Fourside", "img/BluesBrothers.jpg",
"runaway_five_comes_to_fourside.html",
"The Runway Five continues its nationwide tour, stopping in Fourside to perform at the world famous Topolla Theater. Previously, an unexpected delay caused the group to postpone its shows for over a week. The award-winning group was forced to speed ten days in neighboring town, Threed. Tunnels going to and from Threed were blocked, but no one really knows how or why." . "<br>"
."The Runaway Five will being playing at the Topolla Theater during Friday and Saturday night. Tickets are $20 per adult."
);
$articles = Array($runawayFive);
echo $articles[0]["title"];
Должно быть, заголовок статьи повторяется, но я ничего не получаю. Я могу сделать var_dump($articles[0])
и вернуть объект, но не могу получить доступ к его значениям.
Похоже Conde бить вас к нему. –