我目前正在从一个数组中的 sql 语句返回结果,如下所示:
$results = [];
foreach($promotionTool as $p){
$results[] = $p;
}
return $results;
我的控制台在具有以下结构的对象中显示:
(2) [{…}, {…}]
0:
codeID: "41"
code: "123ABC"
rule_type: "Category"
attribute_type: "identifier"
attribute_title: "category number"
attribute_value: "234"
1:
codeID: "41"
code: "123ABC"
rule_type: "Category"
attribute_type: "amount"
attribute_title: "percent"
attribute_value: "25"
这显示了我期望的数据,但我对如何重组它有点迷茫,以便我可以在某些级别上进行分组,最后只返回一个属性数组,如下所示:
codeID
code
rule_type
array(
0:
attribute_type: "identifier"
attribute_title: "category number"
attribute_value: "234"
1:
attribute_type: "amount"
attribute_title: "percent"
attribute_value: "25"
)
我将如何重构我的 foreach 以这种方式在多个级别进行分组?
慕田峪4524236