Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP如果包含多个条件如何?_Php_Json - Fatal编程技术网

PHP如果包含多个条件如何?

PHP如果包含多个条件如何?,php,json,Php,Json,我正在编写一个从JSONAPI读取信息的PHP脚本,目的是从API收集信息并将其放入CSV文件中。我想排除某些信息,到目前为止,我只有一个排除,效果很好,但现在我尝试添加第二个,似乎无法使其正常工作。这是将两个条件结合在一起的正确方法吗 $structure_type = $data['sam_data']['registration']['corporateStructureName']; if($structure_type != "U.S. Government Entity" OR "N

我正在编写一个从JSONAPI读取信息的PHP脚本,目的是从API收集信息并将其放入CSV文件中。我想排除某些信息,到目前为止,我只有一个排除,效果很好,但现在我尝试添加第二个,似乎无法使其正常工作。这是将两个条件结合在一起的正确方法吗

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

我试图做到这一点,如果其中任何一个短语出现在corporateStructureName下,那么它就被排除在外。我认为使用OR是正确的,但它似乎不起作用。

您需要在OR的两边都有完整的表达式

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

另一个更干净、可读性更强的选项是_array($needle,$haystack):


或2个条件
如果($st!='something'&&&$st!='something')
你真的确定你自己找不到这个问题的答案吗,因为互联网上有大量的文档和无数的例子?啊,这是可行的,我没有意识到它必须在双方都完成。谢谢你花时间回答这个问题,我因此学到了一些新东西。谢谢你抽出时间,先生。
<?php
$structureTypes = ['U.S. Government Entity', 'Non-Profit Organization'];
if (!in_array($structureType, $structureTypes)) {
    // ...
}
<?php
if (!($structureType == 'U.S. Government Entity' || $structureType == 'Non-Profit Organization')) {
    // ...
}