<?php declare(strict_types=1); $userScoreA = 80; $userScoreB = 79; function judgeScore(int $score = 0): string { if($score >= 80) { $result = "{$score}点は合格です"; } else { $result = "{$score}点は不合格です"; } return $result; } // echo judgeScore($userScoreA); // echo judgeScore($userScoreB); // echo judgeScore(); function shopping(int $price, int $quantity) :string { $total = $price * $quantity; $result = "合計金額は{$total}円です"; return $result; } // echo shopping(500, 3); function movie(int $age): string { if($age <=12) { return "チケット料金は800円です"; } else if ( $age <= 64 ) { return "チケット料金は1800円です"; } else { return "チケット料金は1100円です"; } } // echo movie(10); function bmi(float $height, int $weight): string { $m = $height / 100; $bmi = $weight / ($m * $m); $roundBmi = round($bmi, 1); if($roundBmi < 18.5) { return "BMIは{$roundBmi}です。低体重です"; } else if ($roundBmi < 25) { return "BMIは{$roundBmi}です。普通体重です"; } else { return "BMIは{$roundBmi}です。肥満です"; } } // echo bmi(164,84); class BookStore{ public string $storename; public string $bookname; public string $outher; public function __construct(string $storename, string $bookname) { $this->storename = $storename; $this->bookname = $bookname; } public function buy() { echo "本を売りました"; } } $store1 = new BookStore("未来書店","走れメロス"); echo $store1->storename; $store1->buy(); echo $store1->bookname; class Cafe{ public string $storename; public string $menu; public int $price; private int $int = 0; function __construct(string $method) { echo "{$menu}を注文しました"; } } $cafe1 = new Cafe("コメダ","コーヒー", 300); echo $cafe1->method;
You have javascript disabled. You will not be able to edit any code.