这里我有一个多维使用这个数组<a *ngFor="let link of item.ReferenceMaterials|split" href="{{link}}">{{link}}</a>
明智地我再制作一个数组,从这个数组我有productId
数组,从这里我必须取Galery
prodcutImage值,如果有任何人更新我的asnwer
我有像这样的数组
first
我试过这样的
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
)
)
答案 0 :(得分:1)
如果我理解了您的要求,您已经尝试过这样的方式将值分配给不同的数组元素,所以只需使用嵌套数组元素访问方式&amp;获取 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']
)
);