如何获得多维数组中的第一个厨房图像值

卡尼R

在这里我productId明智地使用此数组,我正在从这个数组中制作一个数组,再从中获得一个数组,Galery因此我必须采取firstprodcutImage值,如果有人更新我的方法,我将无法实现

我有这样的数组

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何获得多维数组中的一个特定条目

如何根据php中嵌套数组的第一个值对多维数组进行排序?

如果我有一个多维数组,如何只访问第一维的第一个值?

如何使用php中的多维数组显示从最后到第一个的数据

如何获得数组的第一个元素?

从筛选可观察数组中获得第一个值

在TaskEithers数组中获得第一个成功值

如何获得可观察关系链中第一个可观察值的值

如何从图像网址数组中获取第一个jpg / png图像网址?

删除多维数组的第一个数组

多维PHP数组按第一个数组的值分组

如何获得Lua中的第一个表值

如何获得列表中第一个到某些索引值?

如何在Django模板的字典中获得第一个值?

如何在excel中获得第一个非空/空值

遍历多维数组时如何访问键和第一个字符串值?

数组的第一个值

如何从最后一个值到第一个值添加数组中的值

Javascript根据数组的第一个元素从多维数组中删除重复项

Javascript - 计算多维数组的第一个元素

组合多维数组的第一个元素

从JavaScript中的多维数组中删除第一个元素

如何检查数组中的第一个元素

如何在打字稿数组中查找第一个非null值?

如何在Excel数组公式中获取第一个TRUE值

如何在Go模板中访问数组的第一个索引的值

如何返回数组中的第一个非错误值?

如何在数组中搜索多个键并返回第一个找到的值?

如何使用Zapier获取JSON数组中的第一个值?