简体   繁体   English

如何放置多个分组 && , || 使用 if else 的条件

[英]how to put multiple grouped && , || conditions using if else

I want to check conditions with && ||我想用 && || 检查条件groupping it means if one group stisfy then execute the first condition otherwise second and so on so i'll do that with the help of (if else) kindly give me an example分组这意味着如果一个组满足然后执行第一个条件,否则第二个等等所以我会在(如果其他)的帮助下做到这一点,请给我一个例子

Description:-i have a select box with multiple options so diffrent diffrent div will remain open if the selected option value exists in the session.描述:-我有一个带有多个选项的选择框,因此如果会话中存在选定的选项值,则不同的 diffrent div 将保持打开状态。

<div id="bizseg" class="col-sm-4" <?php    if(isset($_SESSION['constitution'])){  if($_SESSION['constitution']=="Individual" && $_SESSION['myprof']=="Self Employed Businessman") {?> style="display:block;" <?php  }else { ?> style="display:none;" <?php }} ?>  style="display:none;">

Shrbham please read what you posted why 2 if statements??? Shrbham 请阅读您发布的内容,为什么 2 if 语句??? if it is all tests for true just && them here is the code and formated so it can be read but in HTML output will be 1 line如果所有测试都为 true 只是 && 它们这里是代码并格式化以便可以读取但在 HTML 输出中将是 1 行

<div id="bizseg" class="col-sm-4" <?php    
    if(
        isset($_SESSION['constitution']) &&
        $_SESSION['constitution'] == $variable &&
        $_SESSION['myprof'] == $variable2 ) {
?> style="display:block;" <?php 
}else { 
?> style="display:none;" <?php } ?>

If's are quite simple true or false如果是很简单的真假

$var1 = "test";
$var2 = "test";
$var3 = "test2";

//so 
$result = $var1 == $var2; // true
$result = $var2 == $var3; // false
//(false)            (true)           // false and anything == false
if($var2 == $var3 && $var1 == $var2); // false
// (false)           (true)           // true or anything == true 
if($var2 == $var3 || $var1 == $var2); // true

if( ($var2 == $var3 || $var1 == $var2) && $var1 == $val3 ) // false
//  ((false)        || (true))         && (false) ==
//  (true)                             && (false) 
//following rules above and false = false;

As "@Lightness Races in Orbit" has said in comments this sort of procedural code is not liked正如“@Lightness Races in Orbit”在评论中所说的那样,不喜欢这种程序代码

you can do it as你可以这样做

<?php    
    if(
        isset($_SESSION['constitution']) &&
        $_SESSION['constitution'] == $variable &&
        $_SESSION['myprof'] == $variable2 ) 
    {
        $result = 'style="display:block;"'; 
    }else {
        $result = 'style="display:none;"';
    }
?>
<div id="bizseg" class="col-sm-4" <?php echo $result ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM