doolo00026 2017-06-28 06:45
浏览 52

在php中推送到多维数组

I have array that contain an score and id that calculated from other function And I have user info that retried from DB.

In Both array ID's are the same how can I push them to One array?

Score Array

Array
(
    [0] => Array
        (
            [id] => 85
            [total_cnt] => 2006
        )

    [1] => Array
        (
            [id] => 86
            [total_cnt] => 1014
        )

    [2] => Array
        (
            [id] => 92
            [total_cnt] => 6
        )

    [3] => Array
        (
            [id] => 93
            [total_cnt] => 6
        )
)

user info

Array
(
    [0] => Array
        (
            [id] => 52
            [user_phone] => 00000000
            [user_email] => test@yahoo.com
            [user_name] => yahoo
            [user_picture] =>FG6K7Z3XTc.Pic.jpg
            [user_post_hour] => 24
            [user_is_block] => 1
            [user_reg_date] => 2017-05-16 13:52:35
        )

    [1] => Array
        (
            [id] => 78
            [user_phone] => 000000001
            [user_email] => google@gmail.com
            [user_name] => google 
            [user_picture] =>XqWKSDVci.Pic.jpg
            [user_post_hour] => 24
            [user_is_block] => 0
            [user_reg_date] => 2017-05-16 13:52:35

        )
)

My Desire output

Array
    (
        [0] => Array
            (
                [id] => 86  <--Same ID in both arrays
                [user_phone] => 00000000
                [user_email] => test@yahoo.com
                [user_name] => yahoo
                [user_picture] =>FG6K7Z3XTc.Pic.jpg
                [user_post_hour] => 24
                [user_is_block] => 1
                [user_reg_date] => 2017-05-16 13:52:35

                [total_cnt] => 1014 <-- first array field added 
            )

I want an optimized code and I won't use loop for to do this

Thanks for your help

  • 写回答

2条回答 默认 最新

  • dongqiu3709 2017-06-28 06:53
    关注

    Use PHP's built-in function array_merge. Use the official PHP documentation for additional guidance @ http://php.net/manual/en/function.array-merge.php

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿