no message

This commit is contained in:
a-kizaki
2026-10-06 12:10:09 +09:00
commit 9c2090ffa2
156 changed files with 14850 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
<?php
// 配列を定義
$fruits = ["Apple", "Banana", "Cherry", "Grape", "Mango"];
// TODO: foreach を使って配列の中身をすべて表示

View File

@@ -0,0 +1,5 @@
<?php
// 配列を定義
$numbers = [10, 20, 30, 40, 50];
// TODO: foreach を使って各値を2倍して表示

View File

@@ -0,0 +1,5 @@
<?php
// 配列を定義
$colors = ["Red", "Blue", "Green", "Yellow", "Black"];
// TODO: foreach を使って要素を表示、"Green"が見つかったらループを終了してください

View File

@@ -0,0 +1,5 @@
<?php
// 配列を定義
$names = ["Taro", "Jiro", "Saburo", "Shiro", "Goro"];
// TODO: foreach を使って "Saburo" のみスキップして表示してください

11
Question07-Array/Ex05.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
// TODO: 連想配列 $user を作成し、以下のデータを格納してください
/*
- "name" => "Taro"
- "age" => 25
- "job" => "Engineer"
*/
// TODO: foreach を使って、キー(key)と値(value)をすべて表示してください
// 例: 「name: Taro」のように表示されるようにする

17
Question07-Array/Ex06.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
// TODO: 連想配列 $people を作成し、以下の人物の名前と年齢を格納してください
/*
- "Taro" => 25
- "Jiro" => 32
- "Saburo" => 28
- "Shiro" => 40
- "Goro" => 35
*/
// TODO: foreach を使って、最年長の人物を見つけてください
// - 最年長の名前を $oldestName に格納する
// - 最年長の年齢を $maxAge に格納する
// TODO: 最年長の人物を以下のフォーマットで表示してください
// 例: 「最年長は Shiro さん(40歳)です。」

21
Question07-Array/Ex07.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
// TODO: 連想配列 $scores を作成し、以下の生徒の名前とテストの点数を格納してください
/*
- "Taro" => 72
- "Jiro" => 85
- "Saburo" => 60
- "Shiro" => 90
- "Goro" => 78
*/
// TODO: foreach を使って、以下の処理を実装してください
// 1. すべての生徒の合計点数を計算する($total に格納)
// 2. 生徒の人数をカウントする($count に格納)
// 3. 平均点を計算し、$average に格納する
// TODO: 計算した平均点を以下のフォーマットで表示してください
// 例: 「テストの平均点: 77 点」
// TODO: foreach を使い、平均点以上の生徒(合格者)を以下のフォーマットで表示してください
// 例: 「合格者: Jiro Shiro Goro」

42
Question07-Array/Ex08.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
/**
*
* 商品データ(カテゴリーごとの売上金額)
* TODO: 連想配列 $sales を定義し、以下のデータを格納してください。
* カテゴリーごとに複数の商品情報が格納された配列とし、各商品の情報は連想配列で表します。
*
* - "Electronics" カテゴリー:
* - Laptop: price = 120000, quantity = 15
* - Smartphone: price = 80000, quantity = 30
* - Tablet: price = 50000, quantity = 20
*
* - "Clothing" カテゴリー:
* - T-Shirt: price = 3000, quantity = 200
* - Jeans: price = 6000, quantity = 150
* - Jacket: price = 15000, quantity = 100
*
* - "Groceries" カテゴリー:
* - Rice: price = 2000, quantity = 500
* - Milk: price = 180, quantity = 1000
* - Eggs: price = 250, quantity = 800
**/
// 各カテゴリーの合計売上を計算
$categorySales = [];
// TODO: foreach を使って、各カテゴリーごとの合計売上金額を計算してください。
// 各商品の売上金額は、"price" × "quantity" で求めます。
// 計算結果は、連想配列 $categorySales に格納してください。
// (キーはカテゴリー名、値はそのカテゴリーの合計売上金額)
// 最高売上のカテゴリーを見つける
$maxCategory = "";
$maxSales = 0;
// TODO: foreach を使って、$categorySales 配列から最も売上が高いカテゴリーを抽出してください。
// 抽出したカテゴリー名と、その売上金額を、それぞれ $maxCategory と $maxSales に格納すること。
// 結果を表示
echo "最高売上のカテゴリーは「{$maxCategory}」で、売上は " . number_format($maxSales) . " 円です。";

View File

@@ -0,0 +1,5 @@
<?php
// ※2次元配列を用いています
$array = array(array(500, 40, 6), array(70, 8, 90, 1000));
// 配列arrayに格納されている全ての数字の平均を出力してください

133
Question07-Array/index.html Normal file
View File

@@ -0,0 +1,133 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PTra07スタートページ</title>
<!-- Bootstrap Core CSS -->
<link href="../common/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="page-header">
<h1>
独習PHP第4章練習問題 <small>配列の活用 / foreach命令</small>
</h1>
</div>
<div class="panel-group" id="accordion">
<!-- ================== PTra07-01-1 ================== -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex01.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Ex01</a> <small>配列の全要素を表示</small>
</h4>
</div>
</div>
<!-- ================== PTra07-01-2 ================== -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex02.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Ex02</a> <small>配列の各要素を加工して表示</small>
</h4>
</div>
</div>
<!-- ================== PTra07-01-3 ================== -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex03.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Ex03</a> <small>特定の要素を見つけたら break する</small>
</h4>
</div>
</div>
<!-- ================== PTra07-01-4 ================== -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex04.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Ex04</a> <small>特定の要素をスキップ</small>
</h4>
</div>
</div>
<!-- ================== PTra07-02-1 ================== -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex05.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Ex05</a>
<small>連想配列の値を表示</small>
</h4>
</div>
</div>
<!-- ================== PTra07-02-02 ================== -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex06.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Ex06</a>
<small>最年長の人物を見つける</small>
</h4>
</div>
</div>
<!-- ================== PTra07-02-03 ================== -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex07.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Ex07</a>
<small>平均点を計算し、合格者を表示</small>
</h4>
</div>
</div>
<!-- ================== PTra07-02-04 ================== -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex08.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Ex08</a>
<small>最高売上の商品カテゴリーを見つける</small>
<h5 style="color: red;">※ +αなので余裕ある方解いてね</h5>
</h4>
</div>
</div>
<!-- ================== PTra07-05 ================== -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex09.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Ex09</a> <small>二次元配列:平均値算出</small>
</h4>
</div>
</div>
</div>
</div>
<!-- jQuery -->
<script src="../common/js/jquery-3.2.1.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="../common/js/bootstrap.min"></script>
</body>
</html>