PHP foreach problem?



Hi All,

I have a php foreach loop that is returning me strange results.
I have an php array $interest as follows:

<?php
$interest 
= array('sports''reading''writing');
?>

Now, print_r($interest) does return me all the values in php array $interest.

Now, when I run foreach in php loop as follows, my output is not placed correctly, but messed up:

<?php
foreach($interest as $key => $title){
    echo 
'<li>' $title '<li>';
}
?>

What is the mistake? Any idea?



If I understand correctly, there could be 2 reasons:
a. Did you close you li tags in ul tag?
b. Looks like you did not close you li tag.


<?php
foreach($interest as $key => $title){
    echo 
'<li>' $title '<li>';
}
?>

should be


<?php
foreach($interest as $key => $title){
    echo 
'<li>' $title '</li>';
}
?>

Do you notice the difference? li tags are closed in the second case.

Thanks. I did not notice li tag closing. I was indeed using ul around li in php foreach loop. Thanks a lot.