templates = $this->get_templates(); } public function get_templates(){ $this->templates = array( 'ol' => array( 'outer' => "
    \n%inner%
\n", 'inner' => "
  • %item%
  • \n" ), 'ul' => array( 'outer' => "\n", 'inner' => "
  • %item%
  • \n" ), 'div' => array( 'outer' => "
    \n%inner%
    \n", 'inner' => "

    %item%

    \n" ), ); } public function get_list( $type = '', $data = array() ){ // get templates if not already set if( empty( $this->templates ) ) $this->get_templates(); // check if the requested list-typ is defined if( ! in_array( $type, array_keys( $this->templates ) ) ) return FALSE; // create list $inner = new stdClass(); $values = new stdClass(); foreach( $data as $key => $value ){ $values->key = $key; $values->item = $value; $inner->inner .= self::sprintf( $this->templates[$type]['inner'], $values ); } return self::sprintf( $this->templates[$type]['outer'], $inner ); } } $data = array( 'Eins', 'Zwei', 'Drei' ); $list = new Lister(); echo $list->get_list( 'ol', $data ); echo $list->get_list( 'ul', $data ); echo $list->get_list( 'div', $data );