How do I negate this if/else comparison to just if? [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to set the class hidden, unless two factors are met. Currently, I'm using the code below:
<?php
if (isset($_POST['prerequisite']) && $form == "CheckingIn")
{
}
else
{
echo "hidden";
}
?>
How can I fix this to just be an if statement instead of an if/else?

Negate the expression; use the "NOT" logical operator:
if (!(isset($_POST['prerequisite']) && $form == "CheckingIn")) { echo "hidden"; }
(notice the ! symbol)
Read more here: http://php.net/manual/en/language.operators.logical.php

Related

Assign empty string to php variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Just need help fixing this php code
if ($cmtx_set_name_value == "anonymous")
{
$cmtx_set_name_value = ""
}
thanks
Try adding ; after the assignment.
$cmtx_set_name_value = "";
your code is work fine just put ; to end of line
if ($cmtx_set_name_value == "anonymous"){
$cmtx_set_name_value = "" ; }

Why does this php function loop endlessly? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Why can't I call this function with the function and increment it's argument?
It seems to loop endlessly without $i incrementing.
function loopy($i) {
loopy($i+1);
echo $i.'...';
if ($i >=5) return true;
}
Because the if statement needs to go before calling the function again to stop it beign an infinite loop:
function loopy($i) {
if ($i >=5) return true;
loopy($i+1);
echo $i.'...';
}

PHP variable and array combinations [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
$nopa = "Shotgun";
$weapon1 = array("Ingen","Shotgun","Glock 17","Revolver","AK 47","Barrett M82");
How can i do so this code will output a yes if the $weapon is equal to $nopa, else it would output a no. Any ideas?
you can use in_array from PHP documentation stated here: http://php.net/manual/en/function.in-array.php
Check the PHP function "in_array"
http://php.net/manual/en/function.in-array.php
if ( in_array($stringVar, $arrayVar) ) {
//do something
}
Careful about case, however.
If needle is a string, the comparison is done in a case-sensitive
manner.
check out the built-in in_array function:
http://php.net/manual/en/function.in-array.php
this is what You want:
<?
$nopa = "Shotgun";
$weapon1 = array("Ingen","Shotgun","Glock 17","Revolver","AK 47","Barrett M82");
if (in_array($nopa,$weapon1)){
echo 'YES';
} else {
echo 'NO';
}
?>
WORKING CODE

I want to perform different type of action based on value is positive or negative [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a sql database where I want to save values
positive in column called credit in
negative in column called credit out
is there any way that php detect that value is positive I know what to do just tell me how to say php that
if(value == +ve){ //do this }else{ //do this }
if( $value >= 0) {
// It's positive (or equal to zero)
} else {
// It's negative
}
To test for positive:
if(value>=0)
if(value > 0){
// do this
}
elseif(value < 0){
// do that
}

Php:Return a String from a function [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The simple program is not returning the string,Please help.
<?php
function returnStr() {
return "fooBar";
}
$str=returnStr();
echo $str;
}
?>
It's a parse error:
$str=returnStr();
echo $str;
} // WHAT IS THIS BRACKET DOING HERE?
There's a fatal error tokenizing the code due the trailing/unmatched '}' remove that and the code will work. Then spend some time thinking about why you didn't know this already
There's an error in your code. The last } is useless.

Categories