Page 1 of 1

in_array usage?

Posted: Mon Jun 19, 2006 9:55 am
by kingconnections
OK so i am trying to do the following: I am having an issue with the inarray. I want to say if $col = computername and is not in $excluded array do this.

I am getting a parse error on the in_array if line. Any ideas?

Code: Select all

foreach ($row as $col=>$val){
    if ($col =="ComputerName" and != in_array("$val", $excluded)) 	
     {
    	
    	
    if ($col =="ComputerName")
          {
        $sitecode = server2site("$val");
          $output .= "  <td class=gray>$sitecode</td><td class =gray> $val</td>\n";
          }
          else
          {
          $output .= "  <td class =gray>$val</td>\n";
          }
          
    }      
    } // end foreach

Posted: Mon Jun 19, 2006 9:57 am
by feyd
remove the equal sign.

Posted: Mon Jun 19, 2006 10:32 am
by kingconnections
ok so i did that and it worked, sort of it did not behave as i expected it too. I changed the code around slightly and it works ok. Here is the fix:

Code: Select all

foreach ($row as $col=>$val){
    if ($col =="ComputerName" and in_array("$val", $excluded)) 	
     {
     	break;
    }
    	
     		
    if ($col =="ComputerName")
          {
          	$row_count++;
        $sitecode = server2site("$val");
          $output .= "<td class=gray>$sitecode</td><td class =gray> $val</td>\n";
          }
          else
          {
  
   $output .= "  <td class =gray>$val</td>\n";
    }
    } // end foreach