doumeng1089 2015-06-22 14:24
浏览 60
已采纳

如何在php中加入两个数组

I have two arrays called $array1 and $array2

and var_dump gives

array (size=1)
  0 => 
    array (size=5)
      'userid' => string '8' (length=1)
      'useremail' => string 'venkat@gmail' (length=12)
      'username' => string 'venkatesh' (length=9)
      'password' => string '1111' (length=4)
      'Name' => string 'venkatesh' (length=9)

array (size=1)
  'modenames' => 
    array (size=3)
      0 => string 'group 4' (length=7)
      1 => string 'group 4' (length=7)
      2 => string 'group 4' (length=7)

now i need to make a json something like this

  {
    "userid":"8",
    "useremail":"venkat@gmail",
    "username":"venkatesh",
    "password":"1111",
    "Name":"venkatesh",
    "modenames":{"group 4","group 4","group 4"}
    }

i have used array_merge() and $array1+$array2 both gives a json not in above format.. help me out.

  • 写回答

4条回答 默认 最新

  • 普通网友 2015-06-22 14:29
    关注

    In this case you need to,

    $t = [
        0 => [
            'userid' => '8',
            'useremail' => 'venkat@gmail',
            'username' => 'venkatesh',
            'password' => '1111',
            'Name' => 'venkatesh'
        ]
    ];
    
    $s = [
        'modenames' => [
            0 => 'group 4',
            1 => 'group 4',
            2 => 'group 4',
        ]
    ];
    
    $t = $t[0] + $s;
    // or
    array_merge($t[0], $s);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?