duanrenzou1619 2017-02-21 12:12
浏览 18
已采纳

too long

Here is my array

array(

    [0] => array(

        [unique_id]   => us - B00SM1YGS6
        [module_id]   => Amazon
        [create_date] => 2017 - 02 - 2101:39:35
        [price]       => 489.00
        [post_id]     => 3127)

    [1] => array(

        [unique_id]   => us - B01G0EURDY
        [module_id]   => Amazon
        [create_date] => 2017 - 02 - 1905:31:43
        [price]       => 799.00
        [post_id]     => 3112)

    [2] => array(
        [unique_id]   => us - B01FZZX9VG
        [module_id]   => Amazon
        [create_date] => 2017 - 02 - 1905:31:43
        [price]       => 199.75
        [post_id]     => 3112,
    ),
)

Now I want to make a new array which will hold the [unique_id] as key and prices as value

But in my array I have same unique_id repeated , so eventually I need something like this

array(
    [us - B00SM1YGS6] => array(price1, price2, price3)
    [us - B01G0EURDY] => array(price1, price2, price3),
)

How to do this ?

Thanks.

  • 写回答

2条回答 默认 最新

  • dongyi1490 2017-02-21 13:18
    关注

    Here is more optimised way of doing it,

    $temp = [];
    foreach ($arr as $key => $value) {
        $temp[$value['unique_id']][] = $value['price']; 
    }
    print_r($temp);
    

    Give it a try, it will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?