我正在对特定表进行查询并得到以下结果:
$results = array(3) {
[0]=>
array(2) {
["category"]=>
string(1) "1"
["manufacturer"]=>
string(1) "2"
}
[1]=>
array(2) {
["category"]=>
string(1) "1"
["manufacturer"]=>
string(1) "9"
}
[2]=>
array(2) {
["category"]=>
string(1) "1"
["manufacturer"]=>
string(2) "10"
}
}
我尝试了许多解决方案,例如:
$temp = array();
foreach ($results as $result) {
foreach ($result as $key => $value) {
$data = array_merge($temp[$key], $value);
}
}
foreach ($results as $result) {
foreach ($result as $key => $value) {
array_push($temp[$result], $value);
}
}
我希望类别的值作为数组的索引,制造商的值作为关联类别(索引)的数组。如下所示 :
$array = array(1) {
[1]=> array(3) {
2,9,10
}
};