in_array usage?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

in_array usage?

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

remove the equal sign.
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post 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
Post Reply