title: PHP - Repetitive code for generating HTML
body: <p>I have the following <strong>Array</strong>s</p>
  
  <pre><code>$elemento = 
  ["title"=&gt; //Level 1
      ["iSh*t","text-center",40,"red"] //Level 2
  ];
  $elemento2 = 
  ["row"=&gt;[ //Level 1
          ["col"=&gt;[  //Level 2
                  ["sm-6"=&gt;[  //Level 3
                          ["text"=&gt;  //Level 4
                              ["Lorem ipsum sit amet","text-center",16,"blue"] //Level 5
                          ]
                      ]
                  ],
                  ["sm-6"=&gt;[  //Level 3
                          ["text"=&gt;  //Level 4
                              ["Lorem ipsum sit amet","text-center",16,"blue"] //Level 5
                          ]
                      ]
                  ],
                  ["sm-6"=&gt;[  //Level 3 
                          ["row"=&gt;[  //Level 4
                                  ["col"=&gt;[  //Level 5
                                          ["sm-6"=&gt;[  //Level 6
                                                  ["title" =&gt;  //Level 7
                                                      ["Lorem ipsum sit amet","text-center",16,"blue"]  //Level 8
                                                  ]
                                              ]
                                          ]
                                      ]   
                                  ],
                                  ["col"=&gt;[  //Level 5
                                          ["sm-6"=&gt;[  //Level 6
                                                  ["title" =&gt;  //Level 7
                                                      ["Lorem ipsum sit amet","text-center",16,"blue"]  //Level 8
                                                  ]
                                              ]
                                          ],
                                          ["sm-6"=&gt;[  //Level 6
                                                  ["title" =&gt;  //Level 7
                                                      ["Lorem ipsum sit amet","text-center",16,"blue"]  //Level 8
                                                  ]
                                              ]
                                          ]
                                      ]   
                                  ]
                              ]   
                          ]
                      ]
                  ]
              ]   
          ]
      ]
  ];
  </code></pre>
  
  <p>I want to create a function than iterates on <strong>every</strong> "level" of my array no matter how many "levels".</p>
  
  <p>Now, I have a function but, yes I know it's not optimized, but I just wanna see how can I make this work.</p>
  
  <pre><code>public function toHTML($superobj,$html){
      $html = "&lt;div class=\"bloque\"&gt;&lt;div class=\"c-c\"&gt;";
      XO::_html_get($superobj,$html);
      $html = $html."&lt;/div&gt;&lt;/div&gt;";
      return $html;
  }
  private function _html_get($superobj,&amp;$html){
      foreach ($superobj as $i =&gt; $val) {
          foreach ($val as $i =&gt; $val) {
              switch ($i) {
                  case 'title':
                      $html = $html."&lt;h1 class=\"".$val[1]."\" style=\"font-size:".$val[2]."px;color:".$val[3]."\"&gt;".$val[0]."&lt;/h1&gt;";
                      break;
                  case 'text':
                      $html = $html."&lt;p class=\"".$val[1]."\"&gt;".$val[0]."&lt;/p&gt;";
                      break;
                  case 'image':
                      $html = $html."&lt;img src=\"".$val[0]."\" class=\"".$val[1]."\"&gt;";
                      break;
                  case 'row':
                      $html = $html."&lt;div class=\"row\"&gt;";
                      foreach ($val as $i =&gt; $val) {
                          foreach ($val as $i =&gt; $val) {
                              if ($i == "columna") {
                                  foreach ($val as $i =&gt; $val) {
                                      $html = $html."&lt;div class=\"col-".array_keys($val)[0]."\"&gt;";
                                          foreach ($val as $i =&gt; $val) {
                                              foreach ($val as $i =&gt; $val) {
                                                  foreach ($val as $i =&gt; $val) {
                                                      if ($i == "texto") {
                                                          $html = $html."&lt;p class=\"".$val[1]."\"&gt;".$val[0]."&lt;/p&gt;";
                                                      }
                                                  }
                                              }
                                          }
                                      $html = $html."&lt;/div&gt;";
                                  }
                              }
                          }
                      }
                      $html = $html."&lt;/div&gt;";
                      break;
                  case 'row':
                      $html = $html."";
                      break;
                  case 'div':
                      $html = $html."";
                      break;
                  case 'button':
                      $html = $html."";
                      break;
                  case 'link':
                      $html = $html."";
                      break;
                  default:
                      # code...
                      break;
              }
          }
      }
  }
  </code></pre>
  
  <p>Now, "working" is, but if I add more levels to level 3 (sm-6) won't work cause the function is not prepared for that..</p>
  
  <blockquote>
    <p>I know this way is <strong>not</strong> optimized and/or recommended, but...</p>
    
    <h2>How can I do this? :)</h2>
  </blockquote>
  
  <p>If you wanna recommend me other way to do this, please don't recommend me frameworks, even if that makes the work and tasks easy, <strong>I will not learn anything</strong>, I love "hand" code.</p>