woops :-)

<?php

function toList ( $array ) {
  $temp = '';

  foreach ( $array AS $item ) {
    if ( is_array ( $item ) ) {
      $temp .= '<li>'.toList ( $array ).'</li>';
    } else {
      $temp .= '<li>'.$item.'</li>';
    }
  }

  return '<ul>'.$temp.'</ul>' ;
}

$array = array ( 10 , 20 , array ( 30 , 40 ) );

echo toList ( $array ) ;

?>

This should now be well formated :-)

Red Wingate wrote:

How about this:

<?php

function toList ( $array ) {
    $temp = '';

    foreach ( $array AS $item ) {
        if ( is_array ( $item ) ) {
            $temp .= '<ul>'.toList ( $array ).'</ul>';
        } else {
        $temp .= '<li>'.$item.'</li>';
        }
    }

    return $temp ;
}

$array = array ( 10 , 20 , array ( 30 , 40 ) );

echo toList ( $array ) ;

?>

Haven't testet it but i think this should work out quite nice :)

Jeff Oien wrote:

Are there any ready made utilities out there for adding HTML
tags to lists? For example if I have:

This Thing
That Thing
The Other Thing
Lot More Things etc.

I would like to have something that would either add <br>
<li></li> (including <ul></ul> at beginning and end) or
<p></p>. If there's nothing out there I'll try to do it myself
but then I'll have to bother you people with questions. :)
Jeff Oien



-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to