回答編集履歴

4

調整

2024/05/14 00:56

投稿

yambejp
yambejp

スコア115916

test CHANGED
@@ -57,6 +57,6 @@
57
57
  $result[]=array_filter($row,fn($x)=>$x!==true);
58
58
  }
59
59
  }
60
- $result=call_user_func_array( "array_map",[null,...$result]);
60
+ $result=call_user_func("array_map",null,...$result);
61
61
  print_r($result);
62
62
  ```

3

再調整

2024/05/13 06:08

投稿

yambejp
yambejp

スコア115916

test CHANGED
@@ -42,3 +42,21 @@
42
42
  $result=call_user_func_array( "array_map", array_merge([null],$result));
43
43
  print_r($result);
44
44
  ```
45
+
46
+ # 今風に
47
+ ```PHP
48
+ <?PHP
49
+ $table = [
50
+ [10, 'Alpha', true,'a1','a2'],
51
+ [13, 'Beta', false,'b1','b2'],
52
+ [15, 'Gamma', true,'c1','c2'],
53
+ [21, 'Delta', true,'d1','d2'],
54
+ ];
55
+ foreach ($table as $row) {
56
+ if(in_array(true,$row, true)) {
57
+ $result[]=array_filter($row,fn($x)=>$x!==true);
58
+ }
59
+ }
60
+ $result=call_user_func_array( "array_map",[null,...$result]);
61
+ print_r($result);
62
+ ```

2

調整

2024/05/13 05:48

投稿

yambejp
yambejp

スコア115916

test CHANGED
@@ -34,8 +34,6 @@
34
34
  [15, 'Gamma', true,'c1','c2'],
35
35
  [21, 'Delta', true,'d1','d2'],
36
36
  ];
37
- $result=[];
38
- $num=2;
39
37
  foreach ($table as $row) {
40
38
  if(in_array(true,$row, true)) {
41
39
  $result[]=array_filter($row,function($x){return $x!==true;});

1

調整

2024/05/13 05:44

投稿

yambejp
yambejp

スコア115916

test CHANGED
@@ -24,3 +24,23 @@
24
24
  unset($tmp);
25
25
  print_r($result);
26
26
  ```
27
+
28
+ # 改良版
29
+ ```PHP
30
+ <?PHP
31
+ $table = [
32
+ [10, 'Alpha', true,'a1','a2'],
33
+ [13, 'Beta', false,'b1','b2'],
34
+ [15, 'Gamma', true,'c1','c2'],
35
+ [21, 'Delta', true,'d1','d2'],
36
+ ];
37
+ $result=[];
38
+ $num=2;
39
+ foreach ($table as $row) {
40
+ if(in_array(true,$row, true)) {
41
+ $result[]=array_filter($row,function($x){return $x!==true;});
42
+ }
43
+ }
44
+ $result=call_user_func_array( "array_map", array_merge([null],$result));
45
+ print_r($result);
46
+ ```