私は、変更が許可されていない関数で動作する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
$ value === trueの場合、どのように通訳者にこれを5倍すると思いますか? – JConstantine
'CalcPlayerPoints'はどのように呼び出されますか? –