title: Rename Laravel Collection Key
body: <p>I have a set of data dictionary <code>$dataDictCollection</code></p>
  <pre><code>&quot;column_a&quot; =&gt; &quot;Column A&quot;,
  &quot;column_b&quot; =&gt; &quot;Column B&quot;,
  &quot;column_c&quot; =&gt; &quot;Column C&quot;,
  &quot;column_d&quot; =&gt; &quot;Column D&quot;,
  &quot;column_e&quot; =&gt; &quot;Column E&quot;,
  </code></pre>
  <p>I have another set of result <code>$resultCollection</code></p>
  <pre><code>[{
      &quot;column_a&quot; =&gt; &quot;value 100&quot;,
      &quot;column_b&quot; =&gt; &quot;value 200&quot;,
      &quot;column_c&quot; =&gt; &quot;value 300&quot;,
      &quot;column_d&quot; =&gt; &quot;value 400&quot;,
      &quot;column_e&quot; =&gt; &quot;value 500&quot;,
  },{
      &quot;column_a&quot; =&gt; &quot;value 110&quot;,
      &quot;column_b&quot; =&gt; &quot;value 220&quot;,
      &quot;column_c&quot; =&gt; &quot;value 330&quot;,
      &quot;column_d&quot; =&gt; &quot;value 440&quot;,
      &quot;column_e&quot; =&gt; &quot;value 550&quot;,
  }]
  </code></pre>
  <p>In the result, I'd like to have the data dictionary's value as the result's key. For example:</p>
  <pre><code>&quot;Column A&quot; =&gt; &quot;value 100&quot;,
  &quot;Column B&quot; =&gt; &quot;value 200&quot;,
  &quot;Column C&quot; =&gt; &quot;value 300&quot;,
  &quot;Column D&quot; =&gt; &quot;value 400&quot;,
  &quot;Column E&quot; =&gt; &quot;value 500&quot;,
  </code></pre>
  <p>Do note that my number of columns are A LOT, I could not specify the key name like below.</p>
  <pre><code>return $data['Column A'] = 'value 100';
  </code></pre>
  <p>I tried <code>mapWithKeys</code>, <code>keyBy</code> but I don't know how to return my desire result.</p>
  <p>I tried</p>
  <pre><code>return collect($resultCollection)-&gt;map(function ($result) use ($dataDictCollection) {
      return collect($dataDictCollection)-&gt;map(function ($dataDic) use ($result) {
          $name[$dataDic] = $result[$dataDic];
          return $name;
      });
  });
  </code></pre>
  <p>But it returns this :(</p>
  <pre><code>&quot;column_a&quot;: {
      &quot;Column A&quot;: &quot;value 100&quot;
  },
  &quot;column_b&quot;: {
      &quot;Column B&quot;: &quot;value 200&quot;
  },
  </code></pre>
  <p>Another attempt</p>
  <pre><code>return collect($resultCollection)-&gt;map(function ($result) use ($dataDictCollection) {
      return collect($result)-&gt;combine($dataDictCollection);
  })-&gt;values();
  </code></pre>
  <p>but it returns like this, reversed and not returning the full data dictionary.</p>
  <pre><code>[{
      &quot;value 100&quot; =&gt; &quot;Column A&quot;,
      &quot;value 200&quot; =&gt; &quot;Column B&quot;,
      &quot;value 300&quot; =&gt; &quot;Column C&quot;,
  },{
      &quot;value 110&quot; =&gt; &quot;Column A&quot;,
      &quot;value 220&quot; =&gt; &quot;Column B&quot;,
      &quot;value 330&quot; =&gt; &quot;Column C&quot;,
  }]    
  </code></pre>