質問編集履歴

1

テストコードを簡素化しました。

2020/01/21 10:32

投稿

mobile105
mobile105

スコア20

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ```PHP
10
10
 
11
- function store_info_view($name){
11
+ function test($name){
12
12
 
13
13
 
14
14
 
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- $GLOBALS['sc_name'] = 'a';
19
+ $GLOBALS['test_name'] = 'aです';
20
20
 
21
21
 
22
22
 
@@ -24,7 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- $GLOBALS['sc_name'] = 'b';
27
+ $GLOBALS['test_name'] = 'bです';
28
28
 
29
29
 
30
30
 
@@ -36,11 +36,11 @@
36
36
 
37
37
 
38
38
 
39
- function store_page(){
39
+ function test_view(){
40
40
 
41
41
 
42
42
 
43
- $store = array_filter(glob($_SERVER['DOCUMENT_ROOT']."/store/*.html"), 'is_file'); //storeの中のhtmlタイトルを配列で全て取得
43
+ $store = ["store-a", "store-b"];
44
44
 
45
45
 
46
46
 
@@ -48,13 +48,11 @@
48
48
 
49
49
 
50
50
 
51
- $store_name = str_replace('.html', "", substr($val, strpos($val, '/store/')+7)); // /store/+7文字以降を切り出し(store-**)
52
-
53
- store_info_view($store_name);
51
+ test($val);
54
52
 
55
53
 
56
54
 
57
- echo $sc_name;
55
+ echo $test_name;
58
56
 
59
57
  }
60
58
 
@@ -78,7 +76,7 @@
78
76
 
79
77
 
80
78
 
81
- function store_info_viewで名前を判別してグローバ変数に代入した値をfunction store_pageで受取りしたいです。
79
+ HTMLファイからstore_page()を呼び出して【aですbです】と表示されるようにしたいです。
82
80
 
83
81
 
84
82
 
@@ -90,33 +88,45 @@
90
88
 
91
89
  ```HTML
92
90
 
93
- <?php require('function.php'); ?>
91
+ require('function.php');
92
+
93
+ $store = ["store-a", "store-b"];
94
94
 
95
95
 
96
96
 
97
- $store = array_filter(glob($_SERVER['DOCUMENT_ROOT']."/store/*.html"), 'is_file'); //storeの中のhtmlタイトルを配列で全て取得
97
+ foreach($store as $val){
98
98
 
99
99
 
100
100
 
101
- foreach($store as $val){
101
+ test($val);
102
102
 
103
103
 
104
104
 
105
- $store_name = str_replace('.html', "", substr($val, strpos($val, '/store/')+7)); // /store/+7文字以降を切り出し(store-**)
105
+ echo $test_name;
106
106
 
107
- store_info_view($store_name);
108
-
109
-
110
-
111
- echo $sc_name;
112
-
113
- }
107
+ }
114
108
 
115
109
 
116
110
 
117
111
  ```
118
112
 
113
+ これの結果は正常に【aですbです】と表示されます。
114
+
115
+ うまく表示されないのは下記のコードです。
116
+
117
+ ```HTML
118
+
119
+ require('function.php');
120
+
121
+ test_view();
122
+
123
+
124
+
125
+ ```
126
+
119
- これは正常に動作し関数としてfunction store_page()を定義してその中でstore_info_view()呼び出のがうまくてないように思います。
127
+ これは何も帰ってきせん。test_view()内で呼び出しているtest($val)関数正常に動いてないように思います。
128
+
129
+
120
130
 
121
131
 
122
132