I have a pretty simple problem.
Basically I have an array called $list
that is a list of titles. If I do a print_r($list)
I get these results:
Array ( [0] => Another New Title [1] => Awesome Movies and stuff [2] => Jascha's Title )
Now, I'm running a foreach
loop to retrieve their values and format them in an <ul>
like so...
function get_film_list(){
global $categories;
$list = $categories->get_film_list();
if(count($list)==0){
echo 'No films are in this category';
}else{
echo '<ul>';
foreach($list as $title){
echo '<li>' . $title . '<li>';
}
echo '</ul>';
}
}
The problem I'm having is my loop is returning开发者_JAVA技巧 two values per value (is it the key value?) The result of the preceding function looks like this:
- Another New Title
- Awesome Movies and stuff
- Jascha's Title
I even tried:
foreach($list as $key => $title){
echo '<li>' . $title . '<li>';
}
With the same results:
- Another New Title
- Awesome Movies and stuff
- Jascha's Title
What am I missing here?
Thanks in advance.
You’re using <li>
instead of </li>
as closing tag. Use the proper closing tag and it should work:
echo '<li>' . $title . '</li>';
精彩评论