在这里我productId
明智地使用此数组,我正在从这个数组中制作一个数组,再从中获得一个数组,Galery
因此我必须采取first
prodcutImage值,如果有人更新我的方法,我将无法实现
我有这样的数组
print_r($productByCode)
Array
(
[0] => Array
(
[productId] => 5
[adminproductId] => 1Delivery00123
[categoryName] => Computer Accessories
[brandName] => Dell
[title] => Dell Inspiron 5000 Series 5547 5555 5557 5558 Internal Laptop Keyboard (Black)
[subTitle] => Dell Keyboard
[price] => 200
[discountType] => Percentage
[discountValue] => 20
[afterDiscount] => 160
[shipppingAmount] => 150
[taxPercentage] => 25
[Galery] => Array
(
[0] => Array
(
[gId] => 13
[productId] => 5
[prodcutImage] => 1.jpeg
)
[1] => Array
(
[gId] => 14
[productId] => 5
[prodcutImage] => 2.jpeg
)
[2] => Array
(
[gId] => 15
[productId] => 5
[prodcutImage] => 3.jpeg
)
)
)
)
我已经试过了
$itemArray = array
(
$productByCode[0]["productId"]=>array
(
'categoryName'=>$productByCode[0]["categoryName"],
'productId'=>$productByCode[0]["productId"],
'brandName'=>$productByCode[0]["brandName"],
'subTitle'=>$productByCode[0]["subTitle"],
'quantity'=>$Qty_total,
'price'=>$productByCode[0]["afterDiscount"],
'taxPercentage'=>$productByCode[0]["taxPercentage"].'%',
'shipppingAmount'=>$productByCode[0]["shipppingAmount"],
'qtyprice'=>round($productByCode[0]["afterDiscount"])
)
);
电流输出
Array
(
[5] => Array
(
[categoryName] => Computer Accessories
[productId] => 5
[brandName] => Dell
[subTitle] => Dell Keyboard
[quantity] => 1
[price] => 160
[taxPercentage] => 25%
[shipppingAmount] => 150
[qtyprice] => 160
)
)
预期产量
Array
(
[5] => Array
(
[categoryName] => Computer Accessories
[productId] => 5
[brandName] => Dell
[subTitle] => Dell Keyboard
[quantity] => 1
[price] => 160
[taxPercentage] => 25%
[shipppingAmount] => 150
[qtyprice] => 160
[prodcutImage] => 1.jpeg
)
)
如果我理解您的要求,您已经尝试过用这种方法将值分配给不同的数组元素,因此,只需使用嵌套数组元素访问方式来获取这样的Galery值,然后将此元素添加到数组的最后。
'prodcutImage' => $productByCode[0]['Galery'][0]['prodcutImage']
所以会这样,
$itemArray = array
(
$productByCode[0]["productId"]=>array
(
'categoryName'=>$productByCode[0]["categoryName"],
'productId'=>$productByCode[0]["productId"],
'brandName'=>$productByCode[0]["brandName"],
'subTitle'=>$productByCode[0]["subTitle"],
'quantity'=>$Qty_total,
'price'=>$productByCode[0]["afterDiscount"],
'taxPercentage'=>$productByCode[0]["taxPercentage"].'%',
'shipppingAmount'=>$productByCode[0]["shipppingAmount"],
'qtyprice'=>round($productByCode[0]["afterDiscount"]),
'prodcutImage' => $productByCode[0]['Galery'][0]['prodcutImage']
)
);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句