selenin Posted June 5, 2010 Share Posted June 5, 2010 Hello, now I made a foreach loop and I wanted to stop it with count < 10 but I don't get it, that's my code: foreach ($results as $res) { echo "<li> <a href='movie.php?mid=".$res->imdbid()."&engine=".$_GET["engine"]."'>".$res-> title()." (".$res->year().")</li>"; } Now I try that it shows only when there are more than 10 only the first 9 Link to comment https://forums.phpfreaks.com/topic/203979-function-in-foreach/ Share on other sites More sharing options...
kenrbnsn Posted June 5, 2010 Share Posted June 5, 2010 The code you posted doesn't have any limiting logic. Try this: <?php $i = 0; foreach ($results as $res) { echo "<li> <a href='movie.php?mid=".$res->imdbid()."&engine=".$_GET["engine"]."'>".$res-> title()." (".$res->year().")</li>"; $i++; if ($i > break; }?> Ken } Link to comment https://forums.phpfreaks.com/topic/203979-function-in-foreach/#findComment-1068362 Share on other sites More sharing options...
selenin Posted June 5, 2010 Author Share Posted June 5, 2010 Thanks a lot Ken, count() was very wrong I started as well with +1 break but was too stupid for it, I still hope one day I won't be a beginner any more... Link to comment https://forums.phpfreaks.com/topic/203979-function-in-foreach/#findComment-1068367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.