PHP - Using explode() function to assign values to an associative array
<p>I'd like to explode a string, but have the resulting array have specific strings as keys rather than integers:</p>

<p>ie. if I had a string "Joe Bloggs", Id' like to explode it so that I had an associative array like:</p>

<pre><code>$arr['first_name'] = "Joe";
$arr['last_name'] = "Bloggs";
</code></pre>

<p>at the moment, I can do:</p>

<pre><code>$str = "Joe Bloggs";
$arr['first_name'] = explode(" ", $str)[0];
$arr['last_name'] = explode(" ", $str)[1];
</code></pre>

<p>which is inefficient, because I have to call explode twice.</p>

<p>Or I can do:</p>

<pre><code>$str = "Joe Bloggs";
$arr = explode(" ", $str);
$arr['first_name'] = $arr[0];
$arr['last_name'] = $arr[1];
</code></pre>

<p>but I wonder if there is any more direct method.</p>

<p>Many thanks.</p>
