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

时间:2015-09-05 11:16:58

标签: javascript php ajax

我想用&&amp ;;检查条件||灌浆意味着如果一个群体满意然后执行第一个条件,否则执行第二个等等,所以我会在(如果有的话)的帮助下做到这一点,请给我一个例子

说明:-i有一个包含多个选项的选择框,因此如果会话中存在所选的选项值,则不同的不同div将保持打开状态。

C:\>exiftool.exe -short -groupNames test.mp4

[ExifTool]      ExifToolVersion                 : 10.61
[File]          FileName                        : test.mp4
[File]          Directory                       : .
[File]          FileSize                        : 91 MB
[File]          FileModifyDate                  : 2018:06:30 19:25:34+05:00
[File]          FileAccessDate                  : 2018:07:15 14:12:50+05:00
[File]          FileCreateDate                  : 2018:07:15 14:12:50+05:00
[File]          FilePermissions                 : rw-rw-rw-
[File]          FileType                        : MP4
[File]          FileTypeExtension               : mp4
[File]          MIMEType                        : video/mp4
[QuickTime]     MajorBrand                      : MP4 v2 [ISO 14496-14]
[QuickTime]     MinorVersion                    : 0.0.0
[QuickTime]     CompatibleBrands                : isom, mp42
[QuickTime]     MovieDataSize                   : 95484206
[QuickTime]     MovieDataOffset                 : 32
[QuickTime]     MovieHeaderVersion              : 0
[QuickTime]     CreateDate                      : 2018:06:30 14:25:34
[QuickTime]     ModifyDate                      : 2018:06:30 14:25:34
[QuickTime]     TimeScale                       : 1000
[QuickTime]     Duration                        : 0:01:02
-- snip --
[QuickTime]     TrackCreateDate                 : 2018:06:30 14:25:34
[QuickTime]     TrackModifyDate                 : 2018:06:30 14:25:34
-- snip --
[QuickTime]     MediaCreateDate                 : 2018:06:30 14:25:34
[QuickTime]     MediaModifyDate                 : 2018:06:30 14:25:34
-- snip --

C:\>exiftool.exe ^
-QuickTime:CreateDate="2018:07:15 13:15:00" ^
-QuickTime:ModifyDate="2018:07:15 13:15:00" ^
-QuickTime:TrackCreateDate="2018:07:15 13:15:00" ^
-QuickTime:TrackModifyDate="2018:07:15 13:15:00" ^
-QuickTime:MediaCreateDate="2018:07:15 13:15:00" ^
-QuickTime:MediaModifyDate="2018:07:15 13:15:00" ^
test.mp4


C:\>exiftool.exe -short -groupNames test.mp4

-- snip --
[File]          FileModifyDate                  : 2018:07:15 14:19:52+05:00
[File]          FileAccessDate                  : 2018:07:15 14:19:51+05:00
[File]          FileCreateDate                  : 2018:07:15 14:19:39+05:00
-- snip --
[QuickTime]     CreateDate                      : 2018:07:15 13:15:00
[QuickTime]     ModifyDate                      : 2018:07:15 13:15:00
-- snip --
[QuickTime]     TrackCreateDate                 : 2018:07:15 13:15:00
[QuickTime]     TrackModifyDate                 : 2018:07:15 13:15:00
-- snip --
[QuickTime]     MediaCreateDate                 : 2018:07:15 13:15:00
[QuickTime]     MediaModifyDate                 : 2018:07:15 13:15:00
-- snip --

1 个答案:

答案 0 :(得分:0)

Shrbham请阅读你发布的内容为什么2如果陈述??? 如果它是真正的所有测试只是&&它们在这里是代码并且格式化,因此可以读取但在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 } ?>

如果真的很简单

$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&#34; @Lightness Races in Orbit&#34;在评论中说这种程序代码不受欢迎

你可以这样做

<?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 ?>