title: Merge multidimensional array of hash based on hash key and value in ruby
body: <p>I have one array and i want to match value of <code>id</code> key with other array of hash in multidimensional array,</p>
  
  <pre><code>input = [ 
    [ {"id"=&gt;"1","name"=&gt;"a"},
      {"id"=&gt;"2","name"=&gt;"b"},
      {"id"=&gt;"3","name"=&gt;"c"},
      {"id"=&gt;"4","name"=&gt;"d"},
      {"id"=&gt;"5","name"=&gt;"e"},
      {"id"=&gt;"6","name"=&gt;"f"}
    ],
    [ {"id"=&gt;"3","hoby"=&gt;"AA"},
      {"id"=&gt;"3","hoby"=&gt;"BB"},
      {"id"=&gt;"1","hoby"=&gt;"CC"},
      {"id"=&gt;"1","hoby"=&gt;"DD"},
      {"id"=&gt;"4","hoby"=&gt;"EE"}
    ],
    [ {"id"=&gt;"1","language"=&gt;"A"},
      {"id"=&gt;"1","language"=&gt;"B"},
      {"id"=&gt;"2","language"=&gt;"B"},
      {"id"=&gt;"2","language"=&gt;"C"},
      {"id"=&gt;"6","language"=&gt;"D"}
    ] 
  ]
  </code></pre>
  
  <p>I need array output like,</p>
  
  <pre><code>output = [ 
    {"id"=&gt;"1","name"=&gt;"a","id"=&gt;"1","hoby"=&gt;"CC","id"=&gt;"1","language"=&gt;"A","id"=&gt;"1","language"=&gt;"B"},
    {"id"=&gt;"2","name"=&gt;"b","id"=&gt;"2","language"=&gt;"B"},
    {"id"=&gt;"3","name"=&gt;"c","id"=&gt;"3","hoby"=&gt;"AA","id"=&gt;"3","hoby"=&gt;"BB"},
    {"id"=&gt;"4","name"=&gt;"d","id"=&gt;"4","hoby"=&gt;"EE"},
    {"id"=&gt;"5","name"=&gt;"e"},
    {"id"=&gt;"6","name"=&gt;"f","id"=&gt;"6","language"=&gt;"D"}
  ]
  </code></pre>
  
  <p>I have wrote code for this,</p>
  
  <pre><code>len = input.length - 1
  output = []
  input[0].each do |value,index|
    for i in 1..len
      input[i].each do |j|
        if value["id"] == j["id"]
          output &lt;&lt; value.merge(j)
        end
      end
    end
  end
  </code></pre>
  
  <p>But i am getting wrong output array.There might be any number of sub array in multidimensional array.</p>
  
  <p>Thank,</p>