googol8080 googol8080 - 1 year ago 71
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download