Concatenate object items
<p>I have the following function which works fine.</p>

<pre><code>function ($objects, $items = array())
{
  $result = array();
  foreach ($objects as $object) {
    $result[$object-&gt;id] = $object-&gt;first_name . ' ' . $object-&gt;last_name; 
  }
  return $result;
}
</code></pre>

<p>However, I would like to pass in an array to $items, and have that exploded, so that I dont have to specify first_name and last_name manually. </p>

<p>If $item was only a single value (and not an array), then it would be simple:</p>

<pre><code>$result[$object-&gt;id] = $object-&gt;$item; 
</code></pre>

<p>But I have no idea how to make this work if $items contains multiple values and I want to join them with a space. Something like, the following, but I need to get the $object in there</p>

<pre><code>$items = array('first_name', 'last_name');
$result[$object-&gt;id] = implode(' ', $items);
</code></pre>
