title: PHP Nested array loop undefined levels
body: <p>I have a multi-dimension nested array. The example below is how the array is nested. However, the amount of levels nested can vary. I need to dynamically loop through them. I would like to do this without using json_encode. Any ideas how I can achieve this?</p>
  
  <pre><code>$array = array(
      'brands' =&gt; array(
          'codes' =&gt; array('b' =&gt; "Apple", 'c' =&gt; 21, 'd' =&gt; 18),
          'items' =&gt; array('b' =&gt; "Google", 'c' =&gt; 22, 'd' =&gt; 19),
          'stock' =&gt; array('b' =&gt; "Samsung", 'c' =&gt; 23, 'd' =&gt; 20)
      )
  );
  </code></pre>
  
  <p><strong>* UPDATE *</strong></p>
  
  <p>I would like the output to look like a json layout but without using json_encode. Should end up looking like the example below. But the levels of the nest can vary:</p>
  
  <pre><code>"brands":{
        "codes":{
           "b":"Apple",
           "c":"21",
           "d":"18"
        },
        "items":{
           "b":"Google",
           "c":"22",
           "d":"19"
        },
        "stock":{
           "b":"Samsung",
           "c":"23",
           "d":"20"
        },
  }
  </code></pre>