public function index()
{
$data = [
[
"spec_id" => 1,
"spec_name" => "颜色",
"value" => [
[
"spec_id" => 1,
"spec_name" => "颜色",
"spec_value_id" => 1,
"spec_value_name" => "红色",
"image" => ""
], [
"spec_id" => 1,
"spec_name" => "颜色",
"spec_value_id" => 2,
"spec_value_name" => "黑色",
"image" => ""
]
]
],
[
"spec_id" => 2,
"spec_name" => "内存",
"value" => [
[
"spec_id" => 2,
"spec_name" => "内存",
"spec_value_id" => 1,
"spec_value_name" => "128G",
"image" => ""
],
[
"spec_id" => 2,
"spec_name" => "内存",
"spec_value_id" => 2,
"spec_value_name" => "256G",
"image" => ""
], [
"spec_id" => 2,
"spec_name" => "内存",
"spec_value_id" => 3,
"spec_value_name" => "512G",
"image" => ""
]
]
],
[
"spec_id" => 3,
"spec_name" => "日期",
"value" => [
[
"spec_id" => 3,
"spec_name" => "日期",
"spec_value_id" => 1,
"spec_value_name" => "02-15",
"image" => ""
],
[
"spec_id" => 3,
"spec_name" => "日期",
"spec_value_id" => 2,
"spec_value_name" => "02-16",
"image" => ""
]
]
],
[
"spec_id" => 4,
"spec_name" => "大中小",
"value" => [
[
"spec_id" => 4,
"spec_name" => "大中小",
"spec_value_id" => 1,
"spec_value_name" => "大",
"image" => ""
],
[
"spec_id" => 4,
"spec_name" => "大中小",
"spec_value_id" => 2,
"spec_value_name" => "中",
"image" => ""
],
[
"spec_id" => 4,
"spec_name" => "大中小",
"spec_value_id" => 3,
"spec_value_name" => "小",
"image" => ""
]
]
]
];
// 最终结果
$result = [];
// 一个规格
foreach ($data[0]['value'] as $item) {
$result[][] = $item;
}
for ($i = 1; $i < count($data); $i++) {
$newResult = [];
foreach ($result as $value1) {
foreach ($data[$i]['value'] as $value2) {
$value = $value1;
array_push($value, $value2);
$newResult[] = $value;
}
}
$result = $newResult;
}
var_dump($result);
}
如何用PHP商品SKU计算
最新推荐文章于 2024-04-26 08:54:06 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)