im은 입력 된 삼각형이 이등변 삼각형인지 등등인지 확인하려고합니다. 첫 번째 if 문은 작동하지만 예기치 않은 t_else를 소개하면 예기치 않은 t_else가됩니다. ...함수의 여러 IF 문 - OOP
public function typeOfTriangle()
{
if ($this->sideOneLength == $this->sideTwoLength && $this->sideTwoLength == $this->baseLength) {
echo "<h1>Equilateral Triangle</h1>";
else if ($this->sideOneLength == $this->sideTwoLength OR $this->sideOneLength == $this->baseLength OR $this->sideTwoLength == $this->baseLength) {
echo "<h1>Isosceles Triangle</h1>";
}
}
아이디어가 있습니까? 아마도 이것은 짝수
public function getSides()
{
return array($this->sideOneLength, $this->sideTwoLength, $this->sideThreeLength);
}
public function typeOfTriangle()
{
$uniqueSides = count(array_unique($this->getSides()));
if ($uniqueSides == 1) {
return "Equilateral";
} elseif ($uniqueSides == 2) {
return "Isosceles";
} else {
return "Normal triangle";
}
}
'echo' 문 뒤에 첫 번째 닫기 중괄호를 잊어 버렸습니다. – jeroen