This class allows you to easily create multi-level ordered, unordered, definition, and custom lists based on an intuitive array structure. Every class I write is aimed at making programming easier. Putting together multi-level HTML lists that validate is one of those tedious things that I set out to simplify. So now, instead of coding:

<ul> 
  <li>List 
    <ul> 
    <li>Item 1</li> 
    <li>Item 2 
      <ul> 
      <li>Sub Item 2</li> 
      </ul></li> 
    </ul></li> 
  <li>More</li> 
  </ul>

To get:

  • List
    • Item 1
    • Item 2
      • Sub Item 2
  • More

Your code will look like:

$li = array(); 
$li[] = 'List'; 
$li[][] = 'Item 1'; 
$li[][] = 'Item 2'; 
$li[][][] = 'Sub Item 2'; 
$li[] = 'More';

Creates a new lister object.

Example
$list = new Lister;

Creates an ordered list from the $array provided.

$array The array with which to create an ordered list. Can either be multi-dimensional, or as in the example below.
$enclose An array of html tags such as 'b', 'big', 'i' etc. that you want to enclose every list item with. I would recommend using a style sheet, but this option is available.
Returns Your ordered list.
Example
$li = array(); 
$li[] = 'List'; 
$li[][] = 'Item 1'; 
$li[][] = 'Item 2'; 
$li[][][] = 'Sub Item 2'; 
$li[] = 'More'; 
 
/* The above array's multi-dimensional counterpart would be: 
$li[0] = array(1=>'List', 5=>'More'); 
$li[1] = array(2=>'Item 1', 3=>'Item 2'); 
$li[3] = array(4=>'Sub Item 2'); 
*/ 
 
$html .= $list->ordered ($li, array('b', 'i'));

Creates an unordered list from the $array provided.

$array The array with which to create an unordered list. Same as in the ordered method.
$enclose An array of html tags that you would like to enclose every list item with.
Returns Your unordered list.
Example
$html .= $list->unordered ($li);

Creates a definition list from the $array provided. This method does not have the enclose option.

$array This array is going to be different than the ones we made for our ordered and unordered lists. All we need are name and value pairs, so the name is the arrays key, and it's value is the array keys value.
Returns Your definition list.
Example
$def['Coffee'] = 'Black hot drink'; 
$def['Milk'] = 'White cold drink'; 
$html .= $list->definition ($def);

This method allows you to create a custom list in case you don't like the flavors that html offers you.

$delimit This is what you would like to indent each line with - spaces, tabs, smiley faces, etc.
$list Your custom list's array. Can either be multi-dimensional, or as in the ordered method example above.
$begin Different from delimit in that it doesn't multiply itself, so this is where you would put your dash, checkmark.gif, multicheck form box, etc.
$end What you want at the end of the line - a <br /> tag most likely.
$enclose An array of html tags that you would like to enclose every list item with.
Returns Your custom list.
Example
$html .= '<pre>' . $list->custom ("\t", $li, '- ', '<br />') . '</pre>';

This is mainly a privately used method, but it comes in so handy for other things that I made it public.

$array The same array as in as in the ordered method example above.
Returns Your multi-dimensional array.
Example
$array = $list->make_multi_dimensional ($li);
Download