回答編集履歴

3

修正

2019/02/06 06:59

投稿

papinianus
papinianus

スコア12705

test CHANGED
@@ -54,9 +54,9 @@
54
54
 
55
55
  function pickParam($new) {
56
56
 
57
- ['action' => $act, 'id' => $id, 'time' => $time] = @array_pop(array_pop($new));
57
+ ['action' => $act, 'id' => $id,/* 'time' => $time*/] = array_pop($new)[0];
58
58
 
59
- return ['action' => $act, 'id' => array_pop($id), 'time' => array_pop($time)];
59
+ return ['action' => $act, 'id' => $id[0],/* 'time' => array_pop($time)*/];
60
60
 
61
61
  }
62
62
 

2

修正

2019/02/06 06:59

投稿

papinianus
papinianus

スコア12705

test CHANGED
@@ -1,3 +1,73 @@
1
+ 明確にされていなかった仕様が想定外のほうになったので、関数作りました。
2
+
3
+ 御社の仕事をするとPHPに対する自信が崩壊していきます。
4
+
5
+
6
+
7
+ ```php
8
+
9
+ var_export(trimmingCopy($new, $current));
10
+
11
+ function trimmingCopy($new, $current) {
12
+
13
+ $param = pickParam($new);
14
+
15
+ $days = array_keys($current);
16
+
17
+ $ret = [];
18
+
19
+ foreach($days as $day) {
20
+
21
+ foreach($current[$day] as $item) {
22
+
23
+ if($item['action'] !== $param['action']) {
24
+
25
+ $ret[$day][] = $item;
26
+
27
+ continue;
28
+
29
+ }
30
+
31
+ $index = array_search($param['id'], $item['id'], true);
32
+
33
+ if($index === false) {
34
+
35
+ $ret[$day][] = $item;
36
+
37
+ continue;
38
+
39
+ }
40
+
41
+ array_splice($item['id'], $index, 1);
42
+
43
+ array_splice($item['time'], $index, 1);
44
+
45
+ $ret[$day][] = $item;
46
+
47
+ }
48
+
49
+ }
50
+
51
+ return $ret;
52
+
53
+ }
54
+
55
+ function pickParam($new) {
56
+
57
+ ['action' => $act, 'id' => $id, 'time' => $time] = @array_pop(array_pop($new));
58
+
59
+ return ['action' => $act, 'id' => array_pop($id), 'time' => array_pop($time)];
60
+
61
+ }
62
+
63
+ ```
64
+
65
+
66
+
67
+ ---
68
+
69
+ deprecated
70
+
1
71
  どっちにしても丸投げですが、添削してほしいのか、作って欲しいのかは明確にしてください。
2
72
 
3
73
 

1

修正

2019/02/06 06:51

投稿

papinianus
papinianus

スコア12705

test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  // 'action' が同じ場合
20
20
 
21
- if($current[$day][$i]['action'] !== $content['action']) {
21
+ if($current[$day][$i]['action'] === $content['action']) {
22
22
 
23
23
  // 'id' が同じ場合
24
24