Don't know how to do that

Discussion in 'PHP' started by selen, Jun 11, 2010.

  1. #1
    Hello, I have $arr as an array with some values, now I want in this foreach, when $res->year() == a value of the $arr not showing, that's my foreach:

    
    $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;
    
    	
    
    }
    PHP:
    I'm far away from a solution
     
    selen, Jun 11, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    how many items are in your array? you are breaking out after 11 times. if you want to show all values in your array then you need to remove this line

    
    if ($i > 11) break;
    
    PHP:
     
    stephan2307, Jun 11, 2010 IP
  3. ram4nd

    ram4nd Active Member

    Messages:
    167
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    50
    #3
    Just make a simple if:
    
    $arr
    $i = 0;
    
    foreach ($results as $res) {
    
    if($res->year() != a) {
    
    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;
    
        
    }
    }
    PHP:
     
    ram4nd, Jun 11, 2010 IP
  4. selen

    selen Well-Known Member

    Messages:
    525
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    118
    #4
    No that's not working, I tried that as well, but $arr is an array with different values and it should be like each value not the same
     
    selen, Jun 12, 2010 IP