googol8080 googol8080 - 1 month ago 5
HTML Question

HTML elements in an array form

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?

Answer

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.

Comments