no message
This commit is contained in:
8
Question01-StartProgram/Ex01.php
Normal file
8
Question01-StartProgram/Ex01.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
// Hello, worldを出力する
|
||||
|
||||
/*
|
||||
* ※print 'Hello, world'; でも同様の結果
|
||||
* 一つのソース内では統一されていることが望ましい
|
||||
*/
|
||||
echo 'Hello, world';
|
||||
10
Question01-StartProgram/Ex02.php
Normal file
10
Question01-StartProgram/Ex02.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
// 変数 value を宣言してください
|
||||
$value;
|
||||
|
||||
// 変数 value に 10(数字) を代入してください
|
||||
$value = 10;
|
||||
|
||||
// 変数 value に入っている値を出力してください
|
||||
echo $value;
|
||||
7
Question01-StartProgram/Ex03.php
Normal file
7
Question01-StartProgram/Ex03.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
// TODO: 変数の命名規則に従っていない変数名を修正してください。
|
||||
|
||||
$value = "100";
|
||||
|
||||
echo $value;
|
||||
18
Question01-StartProgram/Ex04.php
Normal file
18
Question01-StartProgram/Ex04.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
// 配列の宣言と初期化(整数 1, 4, 7, 10, 13 を格納)
|
||||
$array = [1, 4, 7, 10, 13];
|
||||
|
||||
// 配列の値を前から順番に表示(各値の後に改行を追加)
|
||||
foreach ($array as $value) {
|
||||
echo $value . "<br>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 【+αチャレンジ】
|
||||
// 第4章で学ぶ「142ページ or 147ページの方法」を使うと、もっと簡単に書けます!
|
||||
// まだ学んでいないけど、調べて挑戦してみよう!
|
||||
// <?php
|
||||
// $array = [1, 4, 7, 10, 13];
|
||||
// echo implode("<br>", $array);
|
||||
26
Question01-StartProgram/Ex05.php
Normal file
26
Question01-StartProgram/Ex05.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
// TODO: 配列keywordを定義し 「'平', '島', '沼', '山', '森'」 を代入してください
|
||||
$keyword = ['平', '島', '沼', '山', '森'];
|
||||
|
||||
// TODO: 配列keywordに格納されている「沼」のみを表示してください
|
||||
echo $keyword[2];
|
||||
|
||||
// 【+αチャレンジ】
|
||||
// 第4章で学ぶ「制御構文」を使うと、もっと簡単に書けます!
|
||||
// まだ学んでいないけど、調べて挑戦してみよう!
|
||||
// 答え
|
||||
// ↓
|
||||
// // 方法①: for ループを使う
|
||||
// for ($i = 0; $i < count($keyword); $i++) {
|
||||
// if ($keyword[$i] === '沼') {
|
||||
// echo "<br>" . $keyword[$i];
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 方法②: foreach を使う
|
||||
// foreach ($keyword as $word) {
|
||||
// if ($word === '沼') {
|
||||
// echo "<br>" . $word;
|
||||
// }
|
||||
// }
|
||||
20
Question01-StartProgram/Ex06.php
Normal file
20
Question01-StartProgram/Ex06.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/*
|
||||
* TODO: arrayに、以下の表の値を代入してください
|
||||
*
|
||||
* key |値
|
||||
* --------┼---------
|
||||
* name |Suzuki
|
||||
* mail |suzuki@hoge.com
|
||||
* pass |12qwaszx
|
||||
*
|
||||
* */
|
||||
|
||||
$array = [
|
||||
'name' => 'Suzuki',
|
||||
'mail' => 'suzuki@hoge.com',
|
||||
'pass' => '12qwaszx'
|
||||
];
|
||||
|
||||
// TODO: 配列arrayのnameの値を出力してください
|
||||
echo $array['name'];
|
||||
20
Question01-StartProgram/Ex06_α.php
Normal file
20
Question01-StartProgram/Ex06_α.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// // 配列の中に配列がある multiArray を定義
|
||||
// $multiArray = [
|
||||
// [1, 2, 3],
|
||||
// [4, 5, 6],
|
||||
// [7, 8, 9]
|
||||
// ];
|
||||
|
||||
// // multiArray の 2 番目の配列の 3 番目の要素(値 6)を出力
|
||||
// echo $multiArray[1][2] . "<br>"; // 1番目の配列(インデックス1)の2番目の要素(インデックス2)
|
||||
|
||||
// // 配列の中に連想配列がある userList を定義
|
||||
// $userList = [
|
||||
// ["name" => "Tanaka", "age" => 25, "job" => "Engineer"],
|
||||
// ["name" => "Yamada", "age" => 30, "job" => "Designer"],
|
||||
// ["name" => "Sato", "age" => 28, "job" => "Manager"]
|
||||
// ];
|
||||
|
||||
// // userList から "Yamada" の "job" の値("Designer")を出力
|
||||
// echo $userList[1]["job"] . "<br>"; // 2番目の配列(インデックス1)の "job" キーの値
|
||||
9
Question01-StartProgram/Ex07.php
Normal file
9
Question01-StartProgram/Ex07.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
// TODO: 「PHP_BASIC」という名前の定数を "PHPの基礎" にする(const を使用)
|
||||
const PHP_BASIC = "PHPの基礎";
|
||||
// TODO: 「LANGUAGE」という名前の定数を "PHP" にする(define を使用)
|
||||
define("LANGUAGE", "PHP");
|
||||
|
||||
// 定数を表示
|
||||
echo PHP_BASIC . "<br>";
|
||||
echo LANGUAGE;
|
||||
16
Question01-StartProgram/Ex07_α.php
Normal file
16
Question01-StartProgram/Ex07_α.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// 定数を定義し、ディレクトリのパスを管理しよう
|
||||
|
||||
// 「BASE_PATH」を現在のファイルのあるディレクトリに設定
|
||||
define('BASE_PATH', __DIR__); // または const BASE_PATH = __DIR__;
|
||||
|
||||
// 「CONFIG_PATH」を "config/" フォルダのパスとして定義
|
||||
define('CONFIG_PATH', BASE_PATH . "/config/"); // または const CONFIG_PATH = BASE_PATH . "/config/";
|
||||
|
||||
// 定数を表示
|
||||
echo "プロジェクトのルートディレクトリ: " . BASE_PATH . "<br>";
|
||||
echo "設定ファイルのディレクトリ: " . CONFIG_PATH . "<br>";
|
||||
|
||||
// 「CONFIG_PATH」に "database.php" を追加してフルパスを作る
|
||||
$databaseFilePath = CONFIG_PATH . "database.php";
|
||||
echo "データベース設定ファイルのパス: " . $databaseFilePath . "<br>";
|
||||
12
Question01-StartProgram/Ex08.php
Normal file
12
Question01-StartProgram/Ex08.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
// 文字列のエスケープに関する問題
|
||||
|
||||
// シングルクォート内で「I'm learning PHP!」を正しく表現
|
||||
$singleQuoteString = 'I\'m learning PHP!';
|
||||
|
||||
// ダブルクォート内で「He said, "PHP is fun!"」を正しく表現
|
||||
$doubleQuoteString = "He said, \"PHP is fun!\"";
|
||||
|
||||
// 変数を表示
|
||||
echo $singleQuoteString . "<br>";
|
||||
echo $doubleQuoteString . "<br>";
|
||||
23
Question01-StartProgram/Ex08_α.php
Normal file
23
Question01-StartProgram/Ex08_α.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// シングルクォート内で「I'm learning PHP!」を正しく表現
|
||||
$singleQuoteString = 'I\'m learning PHP!';
|
||||
|
||||
// ダブルクォート内で「He said, "PHP is fun!"」を正しく表現
|
||||
$doubleQuoteString = "He said, \"PHP is fun!\"";
|
||||
|
||||
// 変数を定義
|
||||
$name = "Taro";
|
||||
$age = 25;
|
||||
|
||||
// TODO: 変数展開を使い、「My name is Taro. I am 25 years old.」を作成(ダブルクォートを使用)
|
||||
$intro1 = "My name is $name. I am $age years old.";
|
||||
|
||||
// TODO: シングルクォートを使って、同じ文章を作成(連結を使用)
|
||||
$intro2 = 'My name is ' . $name . '. I am ' . $age . ' years old.';
|
||||
|
||||
|
||||
// 変数を表示
|
||||
echo $singleQuoteString . "<br>";
|
||||
echo $doubleQuoteString . "<br>";
|
||||
echo $intro1 . "<br>";
|
||||
echo $intro2 . "<br>";
|
||||
155
Question01-StartProgram/index.html
Normal file
155
Question01-StartProgram/index.html
Normal file
@@ -0,0 +1,155 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>PTra01スタートページ</title>
|
||||
|
||||
<!-- Bootstrap Core CSS -->
|
||||
<link href="../common/css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
独習PHP第2章練習問題 <small>PHPを始めよう</small>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div class="panel-group" id="accordion">
|
||||
<!-- ================== PTra01-01 ================== -->
|
||||
<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>コメントとHello, world</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra01-02 ================== -->
|
||||
<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>
|
||||
|
||||
<!-- ================== PTra01-03 ================== -->
|
||||
<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>変数の命名規則</small>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ================== PTra01-04 ================== -->
|
||||
<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>
|
||||
<!-- ================== PTra01-05 ================== -->
|
||||
<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>
|
||||
<!-- ================== PTra01-06 ================== -->
|
||||
<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>
|
||||
<!-- ================== PTra01-06 + α================== -->
|
||||
<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><br>
|
||||
<h5 style="color: red;">※ +αなので余裕ある方解いてね</h5>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra01-07 ================== -->
|
||||
<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>
|
||||
|
||||
<!-- ================== PTra01-07+α ================== -->
|
||||
<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><br>
|
||||
<h5 style="color: red;">※ +αなので余裕ある方解いてね</h5>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ================== PTra01-08 ================== -->
|
||||
<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>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================== PTra01-08 + α ================== -->
|
||||
<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><br>
|
||||
<h5 style="color: red;">※ +αなので余裕ある方解いてね</h5>
|
||||
</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>
|
||||
Reference in New Issue
Block a user