If variable matches any value in array

Discussion in 'PHP' started by greenlizard, Nov 22, 2010.

Thread Status:
Not open for further replies.
  1. #1
    I want to create an array and if a certain variable matches any value in that array then I want to echo something. This code doesn't work.

    
    <?
    $hide = array(1, 2, 3, 4);
    
    if($number == $hide) {
    echo "";
    }
    ?>
    
    PHP:
    Update, found solution, need to use in_array:

    
    <?
    $hide = array(1, 2, 3, 4);
         if(in_array($number, $hide)) {
         echo "";
    }
    ?>
    
    PHP:

     
    Last edited: Nov 22, 2010
    greenlizard, Nov 22, 2010 IP
Thread Status:
Not open for further replies.