title: Laravel map(): How to alter objects and arrays?
body: <p>I have a multidimensional collection. I want to iterate it and alter some of its child objects and arrays using the map() function: <a href="https://laravel.com/docs/5.1/collections#method-map" rel="noreferrer">https://laravel.com/docs/5.1/collections#method-map</a></p>
  
  <p>Sample content:</p>
  
  <pre><code>[
      {
          'address': 'Somestreet 99'
          'orders': [
              {'id': 11},
              {'id': 67}
          ]
      }
  ]
  </code></pre>
  
  <p>Example</p>
  
  <pre><code>  $deliveries = $delivery_addresses-&gt;map(function($delivery_address){
       $orders = $delivery_address-&gt;orders-&gt;filter(function($order){
          return $order-&gt;id == 67;
       });
  
       $delivery_address['address'] = 'A different street 44'
       $delivery_address['orders'] = $orders;
       $delivery_address['a_new_attribute'] = 'Some data...';
  
       return $delivery_address;
    });
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>[
      {
          'address': 'A different street 44'
          'orders': [
              {'id': 67}
          ],
          'a_new_attribute': 'Some data...;
      }
  ]
  </code></pre>
  
  <p>The result is that only string type variables will be changed. Any arrays or objects will stay the same. Why is this and how to get around it? Thanks! =)</p>