php 数组拼接

[productSkuInfos] => Array

(

[0] => Array

(

[amountOnSale] => 501341

[price] => 16.8

[skuId] => 4540975571942

[specId] => 5e0c897d02565f8eaf273e9840416541

[skuAttributes] => Array

(

[0] => Array

(

[attributeId] => 3216

[attributeName] => 颜色

[attributeNameTrans] => Color

[value] => 白色

[valueTrans] => White

[skuImageUrl] => https://cbu01.alicdn.com/img/ibank/15729264445_698533042.jpg

)

[1] => Array

(

[attributeId] => 100019113

[attributeName] => 适合身高

[attributeNameTrans] => Suitable for height

[value] => 100cm

[valueTrans] => 100cm

)

)

[consignPrice] => 16.8

[cargoNumber] =>

)

[1] => Array

(

[amountOnSale] => 501103

[price] => 16.8

[skuId] => 4540975571936

[specId] => ff10fd0c1265de74343573a7c0ac421a

[skuAttributes] => Array

(

[0] => Array

(

[attributeId] => 3216

[attributeName] => 颜色

[attributeNameTrans] => Color

[value] => 白色

[valueTrans] => White

[skuImageUrl] => https://cbu01.alicdn.com/img/ibank/15729264445_698533042.jpg

)

[1] => Array

(

[attributeId] => 100019113

[attributeName] => 适合身高

[attributeNameTrans] => Suitable for height

[value] => 110(95-105cm)

[valueTrans] => 110(95-105cm)

)

)

[consignPrice] => 16.8

[cargoNumber] =>

)

想拼接一个颜色对应下面多个尺码和价格库存

复制代码
foreach ($data as $k=>$item) {
    $color = '';
    $size = '';
    $newArray = [];
    foreach ($item['skuAttributes'] as $attribute) {
        if ($attribute['attributeName'] === '颜色') {
            $color = $attribute['value'];
        } elseif ($attribute['attributeName'] === '适合身高') {
            $size = $attribute['value'];
            $amountOnSale = $item['amountOnSale'];
            $price = $item['price'];
            $specId = $item['specId'];
        }
    }


    if (!empty($color)) {
        $colorSizeArray[$color][] = ['name_ch'=>$size,'amountOnSale'=>$amountOnSale,'consignPrice'=>$price,'specId'=>$specId];
    }
}
print_r($colorSizeArray);die;

得到结果:

Array

(

[白色] => Array

(

[0] => Array

(

[name_ch] => 100cm

[amountOnSale] => 501341

[consignPrice] => 16.8

[specId] => 5e0c897d02565f8eaf273e9840416541

)

[1] => Array

(

[name_ch] => 110(95-105cm)

[amountOnSale] => 501103

[consignPrice] => 16.8

[specId] => ff10fd0c1265de74343573a7c0ac421a

)

[2] => Array

(

[name_ch] => 120(105-115cm)

[amountOnSale] => 496830

[consignPrice] => 16.8

[specId] => 4b819458d033fae169bd09c85d09dd7b

)

[3] => Array

(

[name_ch] => 130(115-125cm)

[amountOnSale] => 500664

[consignPrice] => 16.8

[specId] => a76e282dfeb129c9e1da9374d8991693

)

[4] => Array

(

[name_ch] => 140(125-135cm)

[amountOnSale] => 501644

[consignPrice] => 16.8

[specId] => 1d71f184a783632ff0d65afe8718dddf

)

[5] => Array

(

[name_ch] => 150(135-145cm)

[amountOnSale] => 499348

[consignPrice] => 16.8

[specId] => c2eca91e89d595b1d3b88e0b638509aa

)

[6] => Array

(

[name_ch] => 160(145-155cm)

[amountOnSale] => 500378

[consignPrice] => 16.8

[specId] => 856a65d84878de75f2293c84567abd0b

)

[7] => Array

(

[name_ch] => L(长度80cm)

[amountOnSale] => 519380

[consignPrice] => 23.0

[specId] => ede0021438e706260e3539e6996c96d7

)

[8] => Array

(

[name_ch] => XL(长度102cm)

[amountOnSale] => 499499

[consignPrice] => 25.0

[specId] => 1130e550943b38dcc81c14eab0412eaa

)

相关推荐
魔众几秒前
一个桌面工具条系统,插件一键启动,快速扩展提高工作效率
开源·php·laravel·blog
向宇it5 分钟前
【从零开始入门unity游戏开发之——C#篇30】C#常用泛型数据结构类——list<T>列表、`List<T>` 和数组 (`T[]`) 的选择
java·开发语言·数据结构·unity·c#·游戏引擎·list
hakesashou11 分钟前
python怎么看矩阵维数
开发语言·python
daopuyun19 分钟前
GB/T34944-2017 《Java语言源代码漏洞测试规范》解读——安全功能
java·开发语言·安全
编程洪同学24 分钟前
Spring Boot 中实现自定义注解记录接口日志功能
android·java·spring boot·后端
qh0526wy31 分钟前
pyqt5冻结+分页表
开发语言·python·qt
hjxxlsx37 分钟前
探索 C++ 自定义函数的深度与广度
开发语言·c++
罗政1 小时前
PDF书籍《手写调用链监控APM系统-Java版》第12章 结束
java·开发语言·pdf
匹马夕阳1 小时前
详细对比JS中XMLHttpRequest和fetch的使用
开发语言·javascript·ecmascript
月巴月巴白勺合鸟月半1 小时前
一个特别的串口通讯
开发语言·串口通讯