conditional-statements

Bash IF : multiple conditions

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 13:09:27
问题 I've been trying to make this thing work for a couple of hours but I can't get it to work : if [ "$P" = "SFTP" -a "$PORT" != "22" ] || [ "$P" = "FTPS" && [ "$PORT" != "990" -a "$PORT" != "21" ] ] ; then Can someone help me ? I know that multiple conditions can be written like this : if [ "$P" = "SFTP" ] && [ "$PORT" != "22" ]; then but how can I imbricate theses conditions like in my first example? 回答1: You can't nest expressions in single brackets. It should be written like this: if [ "$P" =

How to set 'condition' using a condition stored in a property?

 ̄綄美尐妖づ 提交于 2019-12-11 12:54:44
问题 I have a condition such as 'a==1' stored in property $(c) and I wanna used it as the condition for task Message like below code: <PropertyGroup> <aa>1>2</aa> </PropertyGroup> <Target Name="t"> <Message Text="122333" Condition="$(aa)" /> </Target> Error was raised! So, how can I do it? Please help! 回答1: You can easily use property values for evaluating conditions. Here is an example: <PropertyGroup> <aa>1</aa> </PropertyGroup> <Target Name="Build"> <Message Text="Some text" Condition=" $(aa) <

PHP: How can I apply my variables to a dynamic set of conditions?

北慕城南 提交于 2019-12-11 12:12:24
问题 Consider an array as a set of generic or abstract conditional statements: $conditionSet = array( 'condition1' => '$a > $b', 'condition2' => '$c != $d', 'condition3' => '$f < $e' ); Is it possible to apply the variables that I have in my current scope of execution to the conditions in the array on-the-fly - without having to try and parse the statements? i.e. $a = 1; $b = 2; $c = 3; $d = 4; $e = 5; $f = 6; if ( $conditionSet['condition1'] && $conditionSet['condition2'] && $conditionSet[

LESS conditional variable change inside mixin

北城余情 提交于 2019-12-11 12:08:53
问题 I need to achieve such effect, but even when @padding actually < @height it still use multiplier value 2, which is non-sense...Is there any limitation i don't know about? .btn-svg-offset(@height, @padding) { @paddings-n: floor(@height / @padding); @multiplier: 2; & when (@padding < @height) { @multiplier: 1; } @btn-svg-offset: @padding + ((@height / @multiplier) * @paddings-n); }; Any workarounds are welcome) 回答1: & when is not if (they usually say so just for short). & {...} is still a

Symfomy2 get url parameter in routing condition

假如想象 提交于 2019-12-11 11:07:36
问题 I am trying to set up the following route /** * @Route( * "/api/list/{setName}/{order}", * condition= "request.get('order') == 'something' " * * ) */ but I can only produce 404s because the condition is never true although I pass in an order argument. I guess the "request.get('order')" part is wrong, but how to do it? 回答1: try condition= "request.query.get('order') == 'something' " instead of condition= "request.get('order') == 'something' " check more help here and here 回答2: Looking at the

Counting (for each row) how many times an OR condition on several columns is satisfied

房东的猫 提交于 2019-12-11 11:06:40
问题 My question is similar to this one, except a bit different. In the initial question, I was trying to count (for each row) how many columns satisfied a condition. I would like to do something similar, except that the condition involves several columns with an OR condition, and my real data has many columns, so ideally, I'd like to reference the columns using a regular expression. I have the following data: colnames <- c(paste("col",rep(LETTERS[1:2],each=4),rep(1:4,2),sep=""),c("meh","muh")) df

Put IF condition inside a variable

只谈情不闲聊 提交于 2019-12-11 09:38:39
问题 Is there any way to put conditions within a variable and then use that variable in an if statement? See the example below: $value1 = 10; $value2 = 10; $value_condition = '($value1 == $value2)'; if ($value_condition) { echo 'It works!'; } else { echo 'It doesnt work.'; } I understand this may be a bizarre question. I am learning the basics of PHP. 回答1: No need to use strings. Use it directly this way: $value1 = 10; $value2 = 10; $value_condition = ($value1 == $value2); if ($value_condition) {

conditionally multiply a vector by another r

十年热恋 提交于 2019-12-11 09:35:01
问题 I have the following vector trans<- c(-2,3,10,-5,-2,56,0) and I want to multiply each element by a choice of two vectors depending on whether the initial number is positive or negative negtrans<-c(1,2,3) postrans<-c(4,5,6,7) the result should look like this -2 12 50 -10 -6 336 0 the key here is to keep the order intact 回答1: One way is unsplit(Map(`*`, split(trans, trans>=0), list(negtrans, postrans)),trans>=0) #[1] -2 12 50 -10 -6 336 0 回答2: Just multiply the corresponding entries with

Limiting output within a foreach loop

三世轮回 提交于 2019-12-11 08:52:14
问题 I have a multidimensional array, called $alternative , which contains words. This array is dynamically generated, sometimes there may only be 3 words, other times there could be 300 words. In the below code, I am outputting the words from the array to the webpage. How could I limit the output to say, 10 words? foreach ($alternative as $test) { foreach ($test as $test2) { $test3 = ucwords($test2); //Capitalizes first letter of each word printf('<li><a href="related.php?query=%1$s" title="%1$s"

Check if condition in string format in c#

ⅰ亾dé卋堺 提交于 2019-12-11 08:49:32
问题 I am not sure weather its possible or not but I have to do it in my project somehow. I am getting one condition in string format like: string condition = "(param1='69' OR param1='66' OR param1='21' OR param1='93') AND (param2='FL' OR param2='WA) AND (param3!='31' AND param3!='19')"; This condition I am getting from db and I have value of param1, param2 and param3 in my code. Now I have to check this condition in a if statement weather its true of false and show result accordingly. I try like