title: PHP String to multidimensional array
body: <p>Let's say I have the following string in my variable:</p>
  
  <pre><code>$arr['data_|_multilanguage_|_en_|_field'] = 23;
  </code></pre>
  
  <p>I want to transform that into a multidimensional array as follows:</p>
  
  <pre><code>$arr['data']['multilanguage']['en']['field'] = 23;
  </code></pre>
  
  <p>I did a recursive function</p>
  
  <pre><code>foreach ($arr as $outer_key =&gt; $outer_value) {
  
      $parts = explode('_|_', $outer_key);
  
      $reference =&amp; $arr;
      $final_key = count($parts) - 1;
  
      foreach ($parts as $key =&gt; $part) {
          if (!$final_key == $key) {
  
              if (empty($reference[$part])) {
                  $reference[$part] = array();
              }
  
              $reference =&amp; $reference[$part];
  
          } else {
              $reference[$part] = $arr[$str];
              unset($arr[$outer_key]);
          }
      }
  }
  </code></pre>
  
  <p>The problem is that the <code>var_dump</code> shows that the children are reference. Is there a better way?</p>