回答編集履歴
2
修正
test
CHANGED
@@ -16,10 +16,46 @@
|
|
16
16
|
|
17
17
|
<input type="time" name="time" value="<?php echo ($time) ?? "" ?>">
|
18
18
|
|
19
|
-
<input type="time" name="time" value="<?php echo ($time2) ?? "" ?>">
|
19
|
+
<input type="time" name="time2" value="<?php echo ($time2) ?? "" ?>">
|
20
20
|
|
21
21
|
```
|
22
22
|
|
23
23
|
|
24
24
|
|
25
25
|
[Null 合体演算子](https://www.php.net/manual/ja/language.operators.comparison.php#language.operators.comparison.coalesce)
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
`1023`ならこんな感じで、「時間の型が正しいか」関数を作ってチェック。
|
30
|
+
|
31
|
+
```php
|
32
|
+
|
33
|
+
<?php
|
34
|
+
|
35
|
+
function timeFormat($t):string
|
36
|
+
|
37
|
+
{
|
38
|
+
|
39
|
+
if(date("Hi",strtotime($t)) === $t){
|
40
|
+
|
41
|
+
return date("H:i",strtotime($t));
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
return "";
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
$time = "1023";
|
52
|
+
|
53
|
+
$time2 = "";
|
54
|
+
|
55
|
+
?>
|
56
|
+
|
57
|
+
<input type="time" name="time" value="<?php echo timeFormat($time) ?>">
|
58
|
+
|
59
|
+
<input type="time" name="time2" value="<?php echo timeFormat($time2) ?>">
|
60
|
+
|
61
|
+
```
|
1
修正
test
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
DBから取得した情報を$timeにおさめてるならisset($time)は常にtrueになりませんか。(空とnullは別物です)
|
2
2
|
|
3
3
|
|
4
|
+
|
5
|
+
DBのデータの形式次第ですが、そもそも`10:23`のように入っているなら下記だけで良いと思います。
|
4
6
|
|
5
7
|
```php
|
6
8
|
|
7
9
|
<?php
|
8
10
|
|
9
|
-
$time =
|
11
|
+
$time = "10:23";
|
10
12
|
|
11
|
-
|
13
|
+
$time2 = "";
|
12
14
|
|
13
15
|
?>
|
14
16
|
|
15
17
|
<input type="time" name="time" value="<?php echo ($time) ?? "" ?>">
|
18
|
+
|
19
|
+
<input type="time" name="time" value="<?php echo ($time2) ?? "" ?>">
|
16
20
|
|
17
21
|
```
|
18
22
|
|