我有以下簡單的代碼,但它在線this->players[] = 'Tom'
產生語法錯誤:如何在PHP類中定義一個數組屬性
<?php
class club {
var $clubID = 0;
var $players=array();
function __constructor($clubID = '') {
$this->clubID = $clubID;
}
function populatePlayers() {
$this->players[] = 'Tom';
}
}
$myClub = new club(1);
$myClub->populatePlayers();
var_dump($myClub->players);
?>
@Akshay,請編輯時要小心!你向事先不存在的代碼引入了一個問題,現在大多數答案都是無效的! –