title: Laravel collection for loops and mappings
body: <p>I am trying to refactor my code, and remove a for loop. </p>
  
  <pre><code>$result = [];
  foreach ($data as $language) {
      $result[$language-&gt;{$key}] = $language-&gt;{$column};
  }
  </code></pre>
  
  <p>This became:</p>
  
  <pre><code>$result = $data-&gt;map(function($language) use ($key, $column){
      return [$language-&gt;{$key} =&gt; $language-&gt;{$column}];
  });
  </code></pre>
  
  <p>But now instead of:</p>
  
  <pre><code>[
      "key":"value",
      "key":"value"
  ]
  </code></pre>
  
  <p>I am getting</p>
  
  <pre><code>[
      {
          "key":"value"
      },
      {
          "key":"value"
      }
  ]
  </code></pre>
  
  <p>Why doesn't it map like an array?</p>