CodeIgniter Forums
Style output of multidimensional array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Style output of multidimensional array (/showthread.php?tid=51649)



Style output of multidimensional array - El Forum - 05-11-2012

[eluser]BigBonsai[/eluser]
Hello there.

Here is one I have trouble figuring out. Smile

To make this an easy example I have the following table of cars:

ID: 1
Brand: Volkswagen
Color: Yellow

ID: 2
BRAND: BMW
Color: Blue

Say I put this in a multidimensional array like this (coming out of a database, processed by a foreach loop):

Code:
$cars[$row->car_id]['brand'] = $row->car_brand;
$cars[$row->car_id]['color'] = $row->car_color;

This I output with a simple ul($cars), which comes with the html helper.

The output will look something like this:

Code:
<ul>
  <li>1
    <ul>
      <li>Volkswagen</li>
      <li>Yellow</li>
    </ul>
  </li>
  <li>2
    <ul>
      <li>BMW</li>
      <li>Blue</li>
    </ul>
  </li>
</ul>

This works perfect, BUT: What if I do not want to display the ID? Or what if I want to display different colors for each list point of colors or or or? Point is - is there a way to give the different list points style information like class or id?

So something like this would be brilliant:

Code:
<ul id="cars">
  <li class="car_id">1
    <ul class="car_details">
      <li class="car_brand">Volkswagen</li>
      <li class="car_color">Yellow</li>
    </ul>
  </li>
  <li class="car_id">2
    <ul class="car_details">
      <li class="car_brand">BMW</li>
      <li class="car_color">Blue</li>
    </ul>
  </li>
</ul>

I hope I made this halfway understandable. Smile

Thanks for your input. Smile


BiB