0

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?

Thomas Crawford
  • 886
  • 2
  • 15
  • 45

1 Answers1

0

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

Sandeep Varma
  • 322
  • 2
  • 11