我有一個數組中的對象。我想訪問這些對象的屬性,但我沒有任何運氣。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])
並返回該對象,但無法訪問其值。
看起來孔德打敗你吧。 –