dso89762 2016-06-27 13:08
浏览 28

PHP - 重新排列多个数组,以便某些组合具有相同的键(索引)

I have an array, which looks like this:

Array
(
[sku_0017768] => Array
    (
        [0] => 0f359ce5bf6dc855f160c9b89b4aada0
    )

[sku_0017766] => Array
    (
        [0] => ff5a47bd699bcb52944d0727a5b443b6
        [1] => 0f359ce5bf6dc855f160c9b89b4aada0
    )

[sku_0017723] => Array
    (
        [3] => a3c83832b4089d83d164b3cac596fc7e
    )

[sku_0017767] => Array
    (
        [0] => fb91d14d405be52ce989acd2918ea1a0
    )

[sku_8402350] => Array
    (
        [0] => a3c83832b4089d83d164b3cac596fc7e
        [1] => fb91d14d405be52ce989acd2918ea1a0
        [2] => ff5a47bd699bcb52944d0727a5b443b6
        [3] => d14afce16e477663ebe51fdd65cd5010
    )

[sku_8402200] => Array
    (
        [0] => d14afce16e477663ebe51fdd65cd5010
    )

)

Now, this array represents a list of SKU's with one or more 'combination codes'. So, in this example 'sku_0017768' matches product sku_0017766 because they share the same combination code.

sku_8402350 has multiple combination as you can see.

What I need to have now is a new array, where the index(key) of the combination code needs to be same among the other products within the combination.

Output should look like this:

Array
(
[sku_0017768] => Array
    (
       [0] => 0f359ce5bf6dc855f160c9b89b4aada0
    )

[sku_0017766] => Array
    (
       [0] => 0f359ce5bf6dc855f160c9b89b4aada0
       [1] => ff5a47bd699bcb52944d0727a5b443b6
    )

[sku_0017723] => Array
    (
       [0] => a3c83832b4089d83d164b3cac596fc7e
    )


[sku_0017767] => Array
    (
       [0] => fb91d14d405be52ce989acd2918ea1a0
    )

[sku_8402350] => Array
    (
       [0] => fb91d14d405be52ce989acd2918ea1a0
       [1] => ff5a47bd699bcb52944d0727a5b443b6
       [2] => d14afce16e477663ebe51fdd65cd5010
       [3] => a3c83832b4089d83d164b3cac596fc7e
    )

[sku_8402200] => Array
    (
       [2] => d14afce16e477663ebe51fdd65cd5010
    )
)

The difficulty I have is that when a key is already in use, the key of the other products within the combination should increase (with 1) as well, until there is an empty key which the combination can use.

Can anybody help me pointing me in the right direction? Feel free to ask if anything is not clear.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度