回答編集履歴
1
加筆
test
CHANGED
@@ -43,3 +43,55 @@
|
|
43
43
|
```
|
44
44
|
|
45
45
|
![実行結果例](52b82326f69a1c0ca1fc7f2aef887e54.png)
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
---
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
foreach()を使うのなら、こうなるかな。
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```php
|
58
|
+
|
59
|
+
<?php
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
$members = [
|
64
|
+
|
65
|
+
["姓"=>"佐藤","名"=>"一郎","年齢"=>random_int(19,22)],
|
66
|
+
|
67
|
+
["姓"=>"鈴木","名"=>"次郎","年齢"=>random_int(19,22)],
|
68
|
+
|
69
|
+
["姓"=>"田中","名"=>"三郎","年齢"=>random_int(19,22)],
|
70
|
+
|
71
|
+
["姓"=>"高橋","名"=>"四郎","年齢"=>random_int(19,22)],
|
72
|
+
|
73
|
+
["姓"=>"伊藤","名"=>"五郎","年齢"=>random_int(19,22)],
|
74
|
+
|
75
|
+
["姓"=>"渡辺","名"=>"六郎","年齢"=>random_int(19,22)],
|
76
|
+
|
77
|
+
["姓"=>"山本","名"=>"七郎","年齢"=>random_int(19,22)],
|
78
|
+
|
79
|
+
["姓"=>"小林","名"=>"八郎","年齢"=>random_int(19,22)]
|
80
|
+
|
81
|
+
];
|
82
|
+
|
83
|
+
shuffle($members);
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
foreach ($members as $member) {
|
88
|
+
|
89
|
+
if ($member['年齢'] <= 20) {
|
90
|
+
|
91
|
+
echo $member['姓'] . ' ' . $member['名'] . ' ' . $member['年齢'] . PHP_EOL;
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
```
|