I have an Array like this:
[1] "John", "content1"
[2] "John", "content2"
[3] "John", "content3"
[4] "Jim", "content"
[5] "Joana", "content1"
[6] "Joana", "content2"
I attempted to have an output like this:
<ul>
<li>John
<ul>
<li> content 1 </li>
<li> content 2 </li>
<li> content 3 </li>
</ul>
</li>
<li>Jim
<ul>
<li> content </li>
</ul>
</li>
<li>Joana
<ul>
<li> content 1 </li>
<li> content 2 </li>
</ul>
</li>
</ul>
I tried solving it using a foreach-iteration, but it doesn't work out at all: (note: $cur_name means the author's name whereas $content means the content)
foreach($array as $a) {
$cur_name = $a['name'];
if ($old_name != $cur_name && $cur_name !="")$return .= "<li>";
if ($old_name != $cur_name && $cur_name !="") {
$return .= "<strong>$cur_name</strong><br />";
}
elseif($cur_name == "") {
}
elseif ($old_name == $cur_name) {
}
$return .= "$content<br />";
if ($old_name != $cur_name && $cur_name !="") $return .= "</li>";
$old_name = $cur_name;
}
}
Any ideas highliy appreciated..