selenin Posted June 11, 2010 Share Posted June 11, 2010 Hello, it's still a big gap between what I want and what I'm able to, now I built an array and I try that in the foreach the lines with these values don't show up, that's my code: $arr $i = 0; foreach ($results as $res) { echo '<li>'; echo '<a href="'. imdblink($res->imdbid(), $res->year(), $res->title()).'" title="'.$res->title().' '.$res->year().'">'.fewchars("".$res->title()." (".$res->year().")", 35).'</a>'; //echo "<li> <a href='suggest.php?mid=".$res->imdbid()."'>".$res->title()." (".$res->year().")</li>"; echo '</li>'; $i++; if ($i > 11) break; } in this example $arr has these two values: array(2) { [0]=> int(2010) [1]=> int(0) } now I try in my foreach where $res->year() has a value from $arr don't show up, but is a bit too difficult for me Quote Link to comment https://forums.phpfreaks.com/topic/204521-a-question/ Share on other sites More sharing options...
selenin Posted June 11, 2010 Author Share Posted June 11, 2010 when I make a foreach in the foreach and a if not, it loops me all around, I'm really far away from a solution Quote Link to comment https://forums.phpfreaks.com/topic/204521-a-question/#findComment-1070946 Share on other sites More sharing options...
jcbones Posted June 12, 2010 Share Posted June 12, 2010 In your example $arr has nothing to do with the foreach loop. AS the foreach loop is running the array of $results. Quote Link to comment https://forums.phpfreaks.com/topic/204521-a-question/#findComment-1070990 Share on other sites More sharing options...
selenin Posted June 12, 2010 Author Share Posted June 12, 2010 Yes I know, I try when $res->year() has a value of $arr then not show, I tried it like that: foreach ($results as $res) { if($res->year() != $arr) { echo '<li>'; echo '<a href="'. imdblink($res->imdbid(), $res->year(), $res->title()).'" title="'.$res->title().' '.$res->year().'">'.fewchars("".$res->title()." (".$res->year().")", 35).'</a>'; //echo "<li> <a href='suggest.php?mid=".$res->imdbid()."'>".$res->title()." (".$res->year().")</li>"; echo '</li>'; $i++; if ($i > 11) break; //} } } But it doesn't work because $arr is an array and $res->year() has never all values of $arr Quote Link to comment https://forums.phpfreaks.com/topic/204521-a-question/#findComment-1071189 Share on other sites More sharing options...
jcbones Posted June 12, 2010 Share Posted June 12, 2010 Try: if(!in_array($res->year(),$arr)) //if $res->year() is not in the array of $arr. Quote Link to comment https://forums.phpfreaks.com/topic/204521-a-question/#findComment-1071234 Share on other sites More sharing options...
selenin Posted June 12, 2010 Author Share Posted June 12, 2010 Thanks a lot jcbones, that works great Quote Link to comment https://forums.phpfreaks.com/topic/204521-a-question/#findComment-1071252 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.