title: Manipulate string to convert it to another string with different format
body: <p>I have a string in the following form:</p>
  <pre><code>$my_original_string = &quot;A value1,A value2,E value3,A value4&quot;;
  </code></pre>
  <p>The first letter is a sort of label, the value is associated with a label.</p>
  <p>I must manipulate and convert my string to the following:</p>
  <pre><code>$my_converted_string = &quot;A: value1 value2 value4, E: value3&quot;;
  </code></pre>
  <p>With a simple loop, I created an array $temp:</p>
  <pre><code>$my_original_string = &quot;A value1,A value2,E value3,A value4&quot;;
  
  $original_string_to_array = explode(&quot;,&quot;, $my_original_string);
  $o_len = count($original_string_to_array);
  
  $temp = [];
  
  for($i=0; $i&lt;$o_len; $i++){
      $temp[explode(&quot; &quot;,$original_string_to_array[$i])[0]][] = explode(&quot; &quot;,$original_string_to_array[$i])[1];
  }
  
  print_r($temp);
  
  /*
  Result:
  
  Array
  (
      [A] =&gt; Array
          (
              [0] =&gt; value1
              [1] =&gt; value2
              [2] =&gt; value4
          )
  
      [E] =&gt; Array
          (
              [0] =&gt; value3
          )
  
  )
  */
  </code></pre>
  <p>Starting from here, I could eventually loop again to build my new string. Or maybe I could do it even in one loop.</p>
  <p>But, <strong>is there anything better I could do?</strong> I checked the capabilities of <code>array_map</code>, <code>array_filter</code> and <code>array_walk</code> but I could not find a way to apply them in this particular case.</p>
  <p>Thanks in advance.</p>