-4

I know it is already asked few time in this forum but i can't get my answer properly.

I have a variable let it be $val i want to check if it is isset and if it's value is equals to 'something'.

if(isset($val) and $val == "something")
{
Do Something ...
}
else
{
Do Another Thing...
}

Note $val is not array, it is a variable. I got a question like this where $val was array.

Thanks In Advance

Mr. Shrestha
  • 102
  • 2
  • 9

2 Answers2

2

you have to use && operator

 if(isset($val) && $val == "something")
    {
    Do Something ...
    }
    else
    {
    Do Another Thing...
    }

for AND vs && you can refer this

'AND' vs '&&' as operator

Community
  • 1
  • 1
Vision Coderz
  • 8,257
  • 5
  • 41
  • 57
2

just use && logical operators

The standard logical operators and, or, not and xor are supported by PHP. Logical operators first convert their operands to boolean values and then perform the respective comparison.

if(isset($val) && $val == "something"){ }

I tested this one it's also working fine

if(isset($val) and $val == "something"){ }
JYoThI
  • 11,977
  • 1
  • 11
  • 26