PHP - Creating Arrays by Exploded Strings
<p>I have some inputs that I need to process from a form.  The # of inputs from a form depends on the number of languages in my application.  For example, lets say I support english and french:</p>

<pre><code>$input = array(
  'name_1' =&gt; 'Some input in english',
  'content_1' =&gt; 'Some long text in english',
  'name_2' =&gt; 'Some input in french',
  'content_2' =&gt; 'Some long text in french'
);
</code></pre>

<p>...Where '1' and '2' are the IDs of english and french respectively.  What I want to do is explode the strings:</p>

<pre><code>foreach($input as $key=&gt;$val)
{
  $exploded = explode('_', $key);
  $arr = $exploded[1];
  $key = $exploded[2];
}
</code></pre>

<p>..And then push them to separate arrays.  Keep in mind that there could be 2 languages, or 10, so just initializing 2 arrays and checking for '1' or '2' as the $key won't work.</p>

<p>How can I push the values of each to an array so that I end up with an array that look something like this?</p>

<pre><code>$results = array( '1' =&gt; array('name' =&gt; 'Some input in english', 'content' =&gt; 'Some long text in english'), '2' =&gt; array('name' =&gt; 'Some input in french', 'content' =&gt; 'Some long text in french');
</code></pre>

<p>Thanks in advance.  One idea I had was to initialize 2 arrays based off a count of unique key values, but wanted to check first to see if there is a "right" way to do this for a function already there for something like this.</p>
