回答編集履歴

1

2024/02/09 08:40

投稿

melian
melian

スコア19860

test CHANGED
@@ -1,25 +1,21 @@
1
1
  `array_map()` + `implode()` を使うなど。
2
2
  ```php
3
3
  <?php
4
- $days = [
5
- array('date' => '2024-02-08'),
4
+ $days = $cfs->get('date_time');
6
- array('date' => '2024-02-09'),
7
- array('date' => '2024-02-10'),
8
- array('date' => '2024-02-11')
9
- ];
10
5
 
11
- $weekdays = ["日", "月", "火", "水", "木", "金", "土"];
6
+ $weekdays = ["日", "月", "火", "水", "木", "金", "土"];
12
- if ($days):
7
+ if ($days):
13
- $days_string = implode(",",
8
+ $days_string = implode(",",
14
- array_map(function($day) use (&$weekdays) {
9
+ array_map(function($day) use (&$weekdays) {
15
- $dateTime = new DateTimeImmutable($day['date']);
10
+ $dateTime = new DateTimeImmutable($day['date']);
16
- $dayFormat = $dateTime->format('n/j');
11
+ $dayFormat = $dateTime->format('n/j');
17
- $weekday = $weekdays[$dateTime->format('w')];
12
+ $weekday = $weekdays[$dateTime->format('w')];
18
- return $dayFormat . "(" . $weekday . ")";
13
+ return $dayFormat . "(" . $weekday . ")";
19
- }, $days));
14
+ }, $days));
15
+ ?>
16
+ <!-- 日付(曜日)の形式で表示するための <p> タグを出力します -->
20
- echo $days_string;
17
+ <p><?php echo $days_string; ?></p>
18
+ <?php
21
- endif;
19
+ endif;
22
-
23
- // 2/8(木),2/9(金),2/10(土),2/11(日)
20
+ ?>
24
21
  ```
25
-