John C. John C. - 1 month ago 6
JSON Question

PHP IF How to include multiple conditions?

I'm working on a PHP script that reads information from a JSON API, the purpose is to collect the information from the API and put it into a CSV file. I want to exclude certain pieces of information, so far I've only had one exclusion and it worked great but now I'm trying to add a second and can't seem to get it to work correctly. Is this the correct way to join the two conditions together?

$structure_type = $data['sam_data']['registration']['corporateStructureName'];
if($structure_type != "U.S. Government Entity" OR "Non-Profit Organization"){
}


I'm trying to make this so if either one of those phrases comes up under corporateStructureName then it is excluded. I thought using OR was correct but it doesn't seem to function.

Answer

You need to have complete expressions either side of the OR.

if (!($structure_type == "U.S. Government Entity" OR
      $structure_type == "Non-Profit Organization")){
}