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 )

相关推荐
鸿蒙布道师25 分钟前
鸿蒙NEXT开发对象工具类(TS)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei
桃子酱紫君28 分钟前
华为配置篇-BGP实验
开发语言·华为·php
QTX1873040 分钟前
JavaScript 中的原型链与继承
开发语言·javascript·原型模式
shaoing43 分钟前
MySQL 错误 报错:Table ‘performance_schema.session_variables’ Doesn’t Exist
java·开发语言·数据库
The Future is mine1 小时前
Python计算经纬度两点之间距离
开发语言·python
Enti7c1 小时前
HTML5和CSS3的一些特性
开发语言·css3
Harrison_zhu2 小时前
Ubuntu18.04 编译 Android7.1代码报错
android
爱吃巧克力的程序媛2 小时前
在 Qt 创建项目时,Qt Quick Application (Compat) 和 Qt Quick Application
开发语言·qt
独好紫罗兰2 小时前
洛谷题单3-P5719 【深基4.例3】分类平均-python-流程图重构
开发语言·python·算法
篝火悟者2 小时前
自学-C语言-基础-数组、函数、指针、结构体和共同体、文件
c语言·开发语言