标签: conditional

PHP和条件

我正在网上搜索随机密码生成器,我遇到了这段代码

<?php

function generatePassword($length=9, $strength=0) {
    $vowels = 'aeuy';
    $consonants = 'bdghjmnpqrstvz';
    if ($strength & 1) {
        $consonants .= 'BDGHJLMNPQRSTVWXZ';
    }
    if ($strength & 2) {
        $vowels .= "AEUY";
    }
    if ($strength & 4) {
        $consonants .= '23456789';
    }
    if ($strength & 8) {
        $consonants .= '@#$%';
    }

    $password = '';
    $alt = time() % 2;
    for ($i = 0; $i < $length; $i++) {
        if ($alt == 1) {
            $password .= $consonants[(rand() % strlen($consonants))];
            $alt = 0;
        } else …
Run Code Online (Sandbox Code Playgroud)

php conditional ampersand

0
推荐指数
1
解决办法
1208
查看次数

如何在LINQ查询中有条件地加入?

如果我有两张桌子; DriverId和Trips使用外键DriverId和CoDriverId键入的驱动程序,我想查找驱动程序是驱动程序或共同驱动程序的所有行程我可以在Transact-SQL中将其编码为

select d.DriverId, t.TripId 
from Trips t inner join Drivers d 
on t.DriverId = d.DriverId or t.CoDriverId = d.DriverId
Run Code Online (Sandbox Code Playgroud)

如何将其编码为LINQ查询?

linq conditional join

0
推荐指数
1
解决办法
132
查看次数

有条件地传递变量参数

在我的一个iPhone应用程序中,我需要有条件地将变量参数发送到操作表.即

if(condition1)
    otherButtonTitles = @"Button1", @"Button2", nil
else
    otherButtonTitles = @"Button3", @"Button4", nil

UIActionSheet *mediaActionsSheet = [[UIActionSheet alloc] initWithTitle: nil
                                                             delegate: self
                                                    cancelButtonTitle: @"Cancel"
                                               destructiveButtonTitle: nil
                                                    otherButtonTitles: otherButtonTitles];
Run Code Online (Sandbox Code Playgroud)

这样做的语法是什么?应如何定义otherButtonTitles的数据类型?

提前致谢.

此致,Deepa

iphone macos conditional objective-c variadic-functions

0
推荐指数
1
解决办法
276
查看次数

wordpress中的Php条件

有人可以向我解释一下在查看word press中的php用法时经常遇到的替代语法的使用.以条件为例:

我希望看到:

if(10==10)
echo 'this is true and will be shown';
Run Code Online (Sandbox Code Playgroud)

相反,我看到:

if(10==10):
echo 'this is true and will be shown;
end if;
Run Code Online (Sandbox Code Playgroud)

另一个例子:

! empty ( $classes_names ) 
and  $class_names = ' class="'. esc_attr( $class_names ) . '"';
Run Code Online (Sandbox Code Playgroud)

什么是':''结束如果;' 并且最后一个示例语法不是我之前看到的那样的东西.

php wordpress conditional

0
推荐指数
1
解决办法
62
查看次数

哪个是更好的性能明智 - 如果(条件){结果} VS如果(条件)结果;

我知道两种情况下的性能差异都非常小,但我想知道哪种是更实用,性能更高的版本来编写PHP条件.

if(condition){
  result;
}
Run Code Online (Sandbox Code Playgroud)

VS

if(condition)
  result;
Run Code Online (Sandbox Code Playgroud)

php performance conditional curly-brackets

0
推荐指数
1
解决办法
733
查看次数

Javascript更改文本无法正常工作

我有以下javascript代码

  ws.onopen = function() 
  {
    ws.send("running?");
  };

   ws.onmessage = function(evt)
  {
    var phrase = evt.data
    console.log(phrase)
    if(phrase == "1")
    {
    console.log(phrase)
    document.getElementById("Button1").text="Pause"; 
    document.getElementById("Label1").text="Running";
    }   

  };

  //fired when an error occurs during communication with websocket
  ws.onerror = function (error)
  {
    document.getElementById("Label1").innerHTML = "Unknown"
    document.getElementById("Button1").disabled = true; 
  };


  function command() 
  {
    var message = document.getElementById("Button1").value;
    ws.send(message);
  }
Run Code Online (Sandbox Code Playgroud)

这与以下HTML代码一起提供

<html>
<script src="script_control.js" type="text/javascript">
</script>
<p>Script status: <label id="Label1"></label></p>
<button id="Button1" onclick="command()">Pause</button>
</html>
Run Code Online (Sandbox Code Playgroud)

每次短语的值输出到控制台,"1"表示文本编号为1.然而,即使表达式评估尝试,页面上的任何内容都没有任何变化,为什么会发生这种情况呢?

html javascript conditional if-statement

0
推荐指数
1
解决办法
148
查看次数

C#在里面使用!=运算符?:

我正在尝试学习不等式运算符(!=)的工作原理.我可以理解操作员的基本知识.如果操作数不相等则返回"true",否则返回"false".

但我似乎无法围绕编程类中给出的这个特定示例:

  1. 我为Unity编辑器设置了公共字符串,但我没有输入任何文本.
  2. 两个引号("")表示文本在公共字符串上输入.
  3. 但在这种情况下,条件必须是真的吗?因为我没有输入任何文字

为什么条件返回"false"并且控制台调试"Hello Player 1"??? 不是条件"true"因此条件运算符必须返回第一个表达式而不是第二个表达式吗?

public string playerName;

void OnDisable() {
    playerName = (playerName != "") ? playerName : "Player 1";
    Debug.Log("Hello " + playerName);
Run Code Online (Sandbox Code Playgroud)

c# inequality conditional operator-keyword

0
推荐指数
1
解决办法
145
查看次数

嵌套循环和条件语句(Matlab)

如果你有一个随机矩阵,例如5x5:

A(i,j) = (5 4 3 2 1
          4 3 2 1 0
          5 4 3 2 1
          4 3 2 1 0
          5 4 3 2 1)
Run Code Online (Sandbox Code Playgroud)

第二个阵列:

B(1,j) = (4 5 6 7 8)
Run Code Online (Sandbox Code Playgroud)

如果只有当B(1,j)的值大于A的某个colomn值时,才需要将B的值赋值给A?

例如,B(1,1)= 4并且在A的第一个colomn中它大于A(1,1),A(3,1)和A(5,1),所以这些必须被4替换在第二个colomn中,没有什么需要更换,等等.

谢谢!

matlab conditional loops nested

0
推荐指数
1
解决办法
86
查看次数

压缩几个条件语句比较相同的值

我想知道是否有办法压缩这行代码:

elsif i == '+' || i == '-' || i == '/' || i == '*'
Run Code Online (Sandbox Code Playgroud)

ruby conditional if-statement

0
推荐指数
1
解决办法
73
查看次数

如何检查是否没有参数发送给Python中的函数

因此,在一个函数中,我想测试该函数所期望的参数是否存在。如果有自变量,则执行此操作,如果没有从调用程序发送自变量,并且函数中未接收任何自变量,则执行此操作。

def do_something(calculate):
    if calculate == something expected:
        do this
    elif calculate not sent to function:
        do that 
Run Code Online (Sandbox Code Playgroud)

那么,如果没有请自变量进入函数,我需要检查的逻辑测试/表达式是什么?

python conditional function

0
推荐指数
1
解决办法
632
查看次数