我需要在php中編寫一個Player類,它與一個我不允許更改的函數一起工作。我必須以這個函數返回最大值的方式編寫這個類。我只能使用1-10之間的整數。我這裏只複製有問題的一部分:PHP中的嚴格比較
function CalcPlayerPoints($Player) {
$Points = 0;
foreach($Player as $key => $Value) {
switch ($key) {
case "profyears":
if($Value===true) // this should be true
$Points+=($Value*5); // this should take tha value I give in the class construct
break;
case "gentleman":
if($Value===true)
$Points+=10;
break;
}
}
return $Points; // that should be maximized
}
既然我不能改變===比較,我不能初始化profyears屬性。如果我有10初始化,那麼它不if語句輸入...
public function __construct() {
$this->gentleman = true;
$this->profyears = 10;
}
你的問題是什麼? – Crontab 2012-01-30 17:57:19
如果$ value === true,那麼您如何期望解釋器將此乘以5? – JConstantine 2012-01-30 17:59:23
如何調用'CalcPlayerPoints'? – 2012-01-30 18:00:33