質問編集履歴
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,19 +52,239 @@
|
|
52
52
|
|
53
53
|
|
54
54
|
|
55
|
+
|
56
|
+
|
57
|
+
ユーザー 銘柄 銘柄コード 保有株数 株価 資産価値
|
58
|
+
|
59
|
+
1001 トヨタ自動車 7203 500 7127 3563500
|
60
|
+
|
61
|
+
1001 武田薬品工業 4502 300 3763 1128900
|
62
|
+
|
63
|
+
1001 ソニー 6758 100 6758 675800
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
それが下記のPHPです。
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
```php
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
<?php
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
$ai2=htmlspecialchars($_GET['ai2'], ENT_QUOTES, "UTF-8");
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
$user_filepath ="./usr_hold/".$ai2.".csv"; //ユーザー一覧
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
$section_filepath = "./stock/stock_price.csv";
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
$output_file = "output.csv";
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
$user_list = array();
|
96
|
+
|
97
|
+
$section_list = array();
|
98
|
+
|
99
|
+
$output = array();
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
//ユーザー一覧を読み込む
|
104
|
+
|
105
|
+
$user_file = new SplFileObject($user_filepath);
|
106
|
+
|
107
|
+
$user_file->setFlags(SplFileObject::READ_CSV);
|
108
|
+
|
109
|
+
$user_file->setCsvControl("\t");
|
110
|
+
|
111
|
+
$n=0; //先頭行を飛ばすためのカウンタ
|
112
|
+
|
113
|
+
foreach ($user_file as $line){
|
114
|
+
|
115
|
+
if($n>0 && $line[0]!='' && $line[1]!='' && $line[2]!='' && $line[3]!=''){
|
116
|
+
|
117
|
+
$user_list[] =array(
|
118
|
+
|
119
|
+
'ai2_no' => $line[2],
|
120
|
+
|
121
|
+
'stock_name' => $line[3],
|
122
|
+
|
123
|
+
'stock_ai' => $line[4],
|
124
|
+
|
125
|
+
'stock_volume' => $line[5],
|
126
|
+
|
127
|
+
);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
$n++;
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
//所属一覧を読み込む
|
138
|
+
|
139
|
+
$section_file = new SplFileObject($section_filepath);
|
140
|
+
|
141
|
+
$section_file->setFlags(SplFileObject::READ_CSV);
|
142
|
+
|
143
|
+
$section_file->setCsvControl("\t");
|
144
|
+
|
145
|
+
$i=0; //先頭行を飛ばすためのカウンタ
|
146
|
+
|
147
|
+
foreach ($section_file as $line){
|
148
|
+
|
149
|
+
if($i>0 && $line[0]!='' && $line[1]!='' && $line[2]!=''){
|
150
|
+
|
151
|
+
$section_list[] = array(
|
152
|
+
|
153
|
+
'name' => $line[0],
|
154
|
+
|
155
|
+
'ai' => $line[1],
|
156
|
+
|
157
|
+
'price' => $line[2]
|
158
|
+
|
159
|
+
);
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
$i++;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
foreach($user_list as $user_data){
|
172
|
+
|
173
|
+
//ユーザーデータの所属に対応するIDを取得
|
174
|
+
|
175
|
+
$ret = sectionCheck($user_data, $section_list);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
//返り値をユーザーデータに結合する
|
180
|
+
|
181
|
+
$user_data+= $ret;
|
182
|
+
|
183
|
+
$output[] = $user_data;
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
//print_r($output);
|
190
|
+
|
191
|
+
/**************************************
|
192
|
+
|
193
|
+
所属データのIDを返す
|
194
|
+
|
195
|
+
*************************************/
|
196
|
+
|
197
|
+
function sectionCheck($user, $section){
|
198
|
+
|
199
|
+
foreach($section as $s){
|
200
|
+
|
201
|
+
if($user['stock_ai'] == $s['ai']){
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
$ret['ai2_no'] = $user['ai2_no'];
|
206
|
+
|
207
|
+
$ret['stock_name'] = $user['stock_name'];
|
208
|
+
|
209
|
+
$ret['stock_ai'] = $user['stock_ai'];
|
210
|
+
|
211
|
+
$ret['stock_volume'] = $user['stock_volume'];
|
212
|
+
|
213
|
+
$ret['price'] = $s['price'];
|
214
|
+
|
215
|
+
$ret['shisan'] = $s['price']*$user['stock_volume'];
|
216
|
+
|
217
|
+
// $ret['total'] += $ret['shisan'];
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
$ai2_no = $ret['ai2_no'];
|
222
|
+
|
223
|
+
$stock_name = $ret['stock_name'];
|
224
|
+
|
225
|
+
$stock_ai = $ret['stock_ai'];
|
226
|
+
|
227
|
+
$stock_volume = $ret['stock_volume'];
|
228
|
+
|
229
|
+
$price = $ret['price'];
|
230
|
+
|
231
|
+
$shisan = $ret['shisan'];
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
echo "".$ai2_no."\t".$stock_name."\t".$stock_ai."\t".$stock_volume."\t".$price."\t".$shisan."";
|
236
|
+
|
237
|
+
echo "\n";
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
return $ret;
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
```
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
やりたいこと
|
260
|
+
|
261
|
+
総資産価値(資産価値の合計)を7列目に入れたいです。
|
262
|
+
|
55
263
|
1001total.csv
|
56
264
|
|
57
|
-
ユーザー 銘柄
|
265
|
+
ユーザー 銘柄 銘柄コード 保有株数 株価 資産価値 総資産価値
|
58
|
-
|
266
|
+
|
59
|
-
1001
|
267
|
+
1001 トヨタ自動車 7203 500 7127 3563500 5368200
|
60
|
-
|
268
|
+
|
61
|
-
1001
|
269
|
+
1001 武田薬品工業 4502 300 3763 1128900 5368200
|
62
|
-
|
270
|
+
|
63
|
-
1001
|
271
|
+
1001 ソニー 6758 100 6758 675800 5368200
|
272
|
+
|
273
|
+
|
274
|
+
|
64
|
-
|
275
|
+
作ったPHP
|
65
|
-
|
66
|
-
|
276
|
+
|
277
|
+
|
278
|
+
|
67
|
-
|
279
|
+
最終行に下記を加えてみました。
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
$as_total = array_sum(array_column($section, 'shisan'));
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
|
68
288
|
|
69
289
|
|
70
290
|
|
@@ -232,7 +452,15 @@
|
|
232
452
|
|
233
453
|
|
234
454
|
|
455
|
+
|
456
|
+
|
457
|
+
$as_total = array_sum(array_column($section, 'shisan'));
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
|
235
|
-
echo "".$ai2_no."\t".$stock_name."\t".$stock_ai."\t".$stock_volume."\t".$price."\t".$shisan."";
|
463
|
+
echo "".$ai2_no."\t".$stock_name."\t".$stock_ai."\t".$stock_volume."\t".$price."\t".$shisan."\t".$as_total."";
|
236
464
|
|
237
465
|
echo "\n";
|
238
466
|
|
@@ -256,234 +484,6 @@
|
|
256
484
|
|
257
485
|
|
258
486
|
|
259
|
-
やりたいこと
|
260
|
-
|
261
|
-
総資産価値(資産価値の合計)を7列目に入れたいです。
|
262
|
-
|
263
|
-
1001total.csv
|
264
|
-
|
265
|
-
ユーザー 銘柄 銘柄コード 保有株数 株価 資産価値 総資産価値
|
266
|
-
|
267
|
-
1001 トヨタ自動車 7203 500 7127 3563500 5368200
|
268
|
-
|
269
|
-
1001 武田薬品工業 4502 300 3763 1128900 5368200
|
270
|
-
|
271
|
-
1001 ソニー 6758 100 6758 675800 5368200
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
作ったPHP
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
最終行に下記を加えてみました。
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
$as_total = array_sum(array_column($section, 'shisan'));
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
```php
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
<?php
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
$ai2=htmlspecialchars($_GET['ai2'], ENT_QUOTES, "UTF-8");
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
$user_filepath ="./usr_hold/".$ai2.".csv"; //ユーザー一覧
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
$section_filepath = "./stock/stock_price.csv";
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
$output_file = "output.csv";
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
$user_list = array();
|
316
|
-
|
317
|
-
$section_list = array();
|
318
|
-
|
319
|
-
$output = array();
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
//ユーザー一覧を読み込む
|
324
|
-
|
325
|
-
$user_file = new SplFileObject($user_filepath);
|
326
|
-
|
327
|
-
$user_file->setFlags(SplFileObject::READ_CSV);
|
328
|
-
|
329
|
-
$user_file->setCsvControl("\t");
|
330
|
-
|
331
|
-
$n=0; //先頭行を飛ばすためのカウンタ
|
332
|
-
|
333
|
-
foreach ($user_file as $line){
|
334
|
-
|
335
|
-
if($n>0 && $line[0]!='' && $line[1]!='' && $line[2]!='' && $line[3]!=''){
|
336
|
-
|
337
|
-
$user_list[] =array(
|
338
|
-
|
339
|
-
'ai2_no' => $line[2],
|
340
|
-
|
341
|
-
'stock_name' => $line[3],
|
342
|
-
|
343
|
-
'stock_ai' => $line[4],
|
344
|
-
|
345
|
-
'stock_volume' => $line[5],
|
346
|
-
|
347
|
-
);
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
$n++;
|
352
|
-
|
353
|
-
}
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
//所属一覧を読み込む
|
358
|
-
|
359
|
-
$section_file = new SplFileObject($section_filepath);
|
360
|
-
|
361
|
-
$section_file->setFlags(SplFileObject::READ_CSV);
|
362
|
-
|
363
|
-
$section_file->setCsvControl("\t");
|
364
|
-
|
365
|
-
$i=0; //先頭行を飛ばすためのカウンタ
|
366
|
-
|
367
|
-
foreach ($section_file as $line){
|
368
|
-
|
369
|
-
if($i>0 && $line[0]!='' && $line[1]!='' && $line[2]!=''){
|
370
|
-
|
371
|
-
$section_list[] = array(
|
372
|
-
|
373
|
-
'name' => $line[0],
|
374
|
-
|
375
|
-
'ai' => $line[1],
|
376
|
-
|
377
|
-
'price' => $line[2]
|
378
|
-
|
379
|
-
);
|
380
|
-
|
381
|
-
}
|
382
|
-
|
383
|
-
$i++;
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
}
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
foreach($user_list as $user_data){
|
392
|
-
|
393
|
-
//ユーザーデータの所属に対応するIDを取得
|
394
|
-
|
395
|
-
$ret = sectionCheck($user_data, $section_list);
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
//返り値をユーザーデータに結合する
|
400
|
-
|
401
|
-
$user_data+= $ret;
|
402
|
-
|
403
|
-
$output[] = $user_data;
|
404
|
-
|
405
|
-
}
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
//print_r($output);
|
410
|
-
|
411
|
-
/**************************************
|
412
|
-
|
413
|
-
所属データのIDを返す
|
414
|
-
|
415
|
-
*************************************/
|
416
|
-
|
417
|
-
function sectionCheck($user, $section){
|
418
|
-
|
419
|
-
foreach($section as $s){
|
420
|
-
|
421
|
-
if($user['stock_ai'] == $s['ai']){
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
$ret['ai2_no'] = $user['ai2_no'];
|
426
|
-
|
427
|
-
$ret['stock_name'] = $user['stock_name'];
|
428
|
-
|
429
|
-
$ret['stock_ai'] = $user['stock_ai'];
|
430
|
-
|
431
|
-
$ret['stock_volume'] = $user['stock_volume'];
|
432
|
-
|
433
|
-
$ret['price'] = $s['price'];
|
434
|
-
|
435
|
-
$ret['shisan'] = $s['price']*$user['stock_volume'];
|
436
|
-
|
437
|
-
// $ret['total'] += $ret['shisan'];
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
$ai2_no = $ret['ai2_no'];
|
442
|
-
|
443
|
-
$stock_name = $ret['stock_name'];
|
444
|
-
|
445
|
-
$stock_ai = $ret['stock_ai'];
|
446
|
-
|
447
|
-
$stock_volume = $ret['stock_volume'];
|
448
|
-
|
449
|
-
$price = $ret['price'];
|
450
|
-
|
451
|
-
$shisan = $ret['shisan'];
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
$as_total = array_sum(array_column($section, 'shisan'));
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
echo "".$ai2_no."\t".$stock_name."\t".$stock_ai."\t".$stock_volume."\t".$price."\t".$shisan."\t".$as_total."";
|
464
|
-
|
465
|
-
echo "\n";
|
466
|
-
|
467
|
-
}
|
468
|
-
|
469
|
-
}
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
return $ret;
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
```
|
484
|
-
|
485
|
-
|
486
|
-
|
487
487
|
結果
|
488
488
|
|
489
489
|
|