googol8080 googol8080 - 2 months ago 9
HTML Question

HTML elements in an array form

I want to create an array of HTML elements:


<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


How can I output all of them?


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.