HTML elements in an array form

时间:2016-10-20 12:54:07

标签: php html arrays

I want to create an array of HTML elements:

Example

<div class="class"><div class="class2">Some text here</div></div>

here is the array code:

$arr = array('div' => array('class' => 'class'), 'div' => array('class' => 'class2'));

Here is how I use foreach loop:

foreach ($arr as $type => $key) {
   foreach ($key as $keys => $value) {
      $arrays .= '<' . $keys . '="' . $value . '">';
   }
}

echo $arrays;

Here is the result

<class="class2">

How can I output all of them?

1 个答案:

答案 0 :(得分:1)

You can't. Your problem is, that you have duplicate keys in your array. In that case only the last value of that particular key is left in the array. Your only chance is to recreate the array so it does not have duplicate keys.