SHARE
TWEET

Untitled

a guest Jun 17th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <h5>STEP1</h5>
  2. <?php
  3. echo "PHP!!"
  4. ?>
  5.  
  6.  
  7. <h5>STEP2</h5>
  8. <p>・問題1</p>
  9. <?php
  10. $n = 6;
  11. if (n < 10) {
  12.   echo "small";
  13. } else {
  14.   echo "large";
  15. }
  16. ?>
  17.  
  18. <p>・問題2</p>
  19. <?php
  20. $a = 5;
  21. $b = 1;
  22. if ($a < $b) {
  23.   echo $a;
  24. } else {
  25.   echo $b;
  26. }
  27. ?>
  28.  
  29. <p>・問題3</p>
  30. <?php
  31. $a = 5;
  32. $b = 1;
  33. $tmp = $a;
  34. $a = $b;
  35. $b = $tmp;
  36. echo "a = ${a}, ";
  37. echo "b = ${b}";
  38. ?>
  39.  
  40. <p>・問題4</p>
  41. <?php
  42. for($i=0; $i<10; $i++) {
  43.   echo $i;
  44. }
  45. ?>
  46.  
  47. <p>・問題5</p>
  48. <?php
  49. $n = 10;
  50. for($i=0; $i<=$n; $i++) {
  51.   for($t=0; $t<$i; $t++) {
  52.     echo "x";
  53.   }
  54.   echo "<br/>";
  55. }
  56. ?>
  57.  
  58. <p>・問題6</p>
  59. <?php
  60. $array = [1, 2, 3];
  61. print_r($array);
  62. ?>
  63.  
  64. <p>・問題7</p>
  65. <?php
  66. $array = [1, 2, 3];
  67. for($i=0; $i<count($array); $i++) {
  68.   echo $array[$i] . "<br/>";
  69. }
  70. ?>
  71.  
  72. <p>・問題8</p>
  73. <?php
  74. $a = [3, 5, 7];
  75. array_push($a, 3, 6, 7, 8);
  76. $a = array_unique($a);
  77. print_r($a);
  78. ?>
  79.  
  80. <p>・問題9</p>
  81. <?php
  82. $array = [1, 2, 3];
  83. function sum($array) {
  84.   $a = count($array);
  85.   for($i=0; $i<$a; $i++) {
  86.     $n += $array[$i];
  87.   }
  88.   echo $n;
  89. }
  90. sum($array)
  91. ?>
  92.  
  93. <p>・問題10</p>
  94. <?php
  95. $array = [1, 2, 3];
  96. function average($array) {
  97.   $count = count($array);
  98.   for($i=0; $i<$count; $i++) {
  99.     $n += $array[$i];
  100.   }
  101.   $s = $n / $count;
  102.   echo $s;
  103. }
  104. average($array)
  105. ?>
  106.  
  107. <p>・問題11</p>
  108. <ul>
  109.   <?php
  110.   $nums = [1, 2, 3];
  111.   foreach ($nums as $n) :
  112.   ?>
  113.   <li><?php echo "$n"."<br/>"; ?></li>
  114.   <?php endforeach; ?>
  115. </ul>
  116.  
  117. <p>・問題12</p>
  118. <?php
  119. $nums = [1, 2, 3, 4, 5, 6, 7];
  120. function echo_array($nums) {
  121.   $new_nums = [];
  122.   foreach ($nums as $n) :
  123.     $s += $n;
  124.     if ($s > 15) {
  125.       break;
  126.     }
  127.     array_push($new_nums, $n);
  128.   endforeach;
  129.   print_r($new_nums);
  130. }
  131. echo_array($nums)
  132. ?>
  133.  
  134. <p>・問題13</p>
  135. <?php
  136. $hash = array("key1" => 1, "key2" => 2, "key3" => 3);
  137. print_r($hash);
  138. ?>
  139.  
  140. <p>・問題14</p>
  141. <?php
  142. echo $hash["key2"];
  143. ?>
  144.  
  145. <p>・問題15</p>
  146. <?php
  147. $new_hash = array_merge($hash, array("key4" => 4));
  148. print_r($new_hash);
  149. ?>
  150.  
  151. <p>・問題16</p>
  152. <?php
  153. foreach ($new_hash as $key => $value) :
  154.   echo "\"" . $key . "\nis\n " . $value . "\"<br/>";
  155. endforeach
  156. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top