doufu7464 2016-05-10 09:41
浏览 80

在值上合并数组

I have the following array which i want to merge with another array.

The 2 arrays : ( There are actually much more items in the response but for now i want to merge the array on a specific value ).

array (size=5)
  '_index' => string 'pagespeed' (length=9)
  '_type' => string 'ecostylenlresult' (length=16)
  '_id' => string 'AVSaAaavHgv4xDNlwI0f' (length=20)
  '_score' => float 1
  '_source' => 
    array (size=9)
      'kind' => string 'pagespeedonline#result' (length=22)
      'id' => string 'http://www.ecostyle.nl/' (length=23)
      'responseCode' => int 200
      'title' => string 'ECOstyle |' (length=10)
      'ruleGroups' => 
        array (size=1)
          'SPEED' => 
            array (size=1)
              ...
      'pageStats' => 
        array (size=10)
          'numberResources' => int 60
          'numberHosts' => int 7
          'totalRequestBytes' => string '6997' (length=4)
          'numberStaticResources' => int 56
          'htmlResponseBytes' => string '40101' (length=5)
          'cssResponseBytes' => string '332781' (length=6)
          'imageResponseBytes' => string '2160470' (length=7)
          'javascriptResponseBytes' => string '286189' (length=6)
          'numberJsResources' => int 26
          'numberCssResources' => int 14
      'formattedResults' => 
        array (size=2)
          'locale' => string 'en_US' (length=5)
          'ruleResults' => 
            array (size=10)
              ...
      'version' => 
        array (size=2)
          'major' => int 1
          'minor' => int 15
      0 => string 'ecostylenl_2016-05-10' (length=21)


array (size=5)
  '_index' => string 'moz' (length=3)
  '_type' => string 'ecostylenlresult' (length=16)
  '_id' => string 'AVSaAZUbHgv4xDNlwI0c' (length=20)
  '_score' => float 1
  '_source' => 
    array (size=12)
      'fmrp' => float 5.1715406017042
      'fmrr' => float 1.2509523237227E-8
      'pda' => float 48.09425912773
      'ueid' => int 3620
      'uid' => int 7085
      'umrp' => float 6.8994293440141
      'umrr' => float 7.137551640113E-8
      'upa' => float 56.852760548224
      'us' => int 200
      'ut' => string 'ECOstyle' (length=8)
      'uu' => string 'www.ecostyle.nl/' (length=16)
      0 => 
        array (size=1)
          '' => string 'ecostylenl_2016-05-10' (length=21)

In both of these arrays i have the same value.

0 => string 'ecostylenl_2016-05-10' (length=21)

I want to make 1 array of this, so i have all the results in 1 element.

What is the best way to do this?

  • 写回答

1条回答 默认 最新

  • doulong4169 2016-05-10 09:56
    关注

    array_merge function of php might help you to achieve this. It merge one or more arrays together.

    If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.

    Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.

    You can refer about this at: enter link description here

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算