1
class Player
{
public $name;
public $stack;
public $action;
public function __construct($stack, $action)
{
$this->action = $action;
$this->stack = $stack;
}
}
class Hand
{
public $BB;
public $SB;
public $ante;
public $isSB = TRUE;
public $hero = 1;
public $players = array(
new Player(1800,200);
new Player(2000,0);
new Player(2400,100);
new Player(2600,200);
);
}
$h = new Hand();
echo $h->players[$h->hero]->stack;
我得到了解析錯誤。 解析錯誤:語法錯誤,意外的T_NEW,期待')'在... 如何添加對象到這個數組?有更好的解決方案嗎?PHP - 數組中的新對象
你不能做到這一點。數組中的第一項由逗號分隔。其次:你需要在一個方法中做到這一點。 – PeeHaa