define関数では、定数を定義することができる。
一度データとして格納すると変更できない。
サンプルとして、金利15%・毎月5000円支払いのリボ払いで購入した場合、何カ月で払い終えるか見てみましょう。
<?php
define("revolving", "5000");
class Card{
public $amount;
public $i = 0;
function revo(){
while($this->amount>0){
$this->amount = $this->amount * (0.15/12 + 1) - revolving;
$this->i++;
}
echo $this->i+1 ."<br>\n";
}
}
$gucci = new Card();
$gucci->amount = 50000;
$gucci->revo();
$chanel = new Card();
$chanel->amount = 80000;
$chanel->revo();
?>
