コードは「私はロサンゼルスに行く予定です。旅は300マイルの距離になります。私のIF文で定義されている数に応じて、複数の単語または単数の単語を「停止」する必要がある場合(その場合は、複数形にする必要があります)。私はクラスを構築した方法のためにIFが期待通りに動作しないと思います。それを修正するどんな助けもありがたいです。IFのステートメントが正しく解決されない
class trip {
public $destination;
public $distance;
public $unit;
public $stops = null;
public $transport = null;
function __construct($destination, $distance, $unit, $stops, $transport) {
$this->destination = $destination;
$this->distance = $distance;
$this->unit = $unit;
$this->stops = $stops;
$this->transport = $transport;
}
function getTrip() {
$a = "I will be going to " . $this->destination . ". ";
$a .= "The journey will be a distance of " . $this->distance . " " . $this->unit . ". ";
$a .= "We will need to make " . $this->stops;
if ($this->stops = 1) {
$a .= " stop.";
} else {
$a .= " stops.";
}
$a .= "\n";
echo $a;
}
}
$first = new trip('Los Angeles',300,'miles',2,'airplane');
$first->getTrip();
同じ回答が発生する異なる質問は重複しません。余分なポイントをいくつか得点するために必要な節度は、Stackoverflow製品を傷つけることです。 – Andy