0

If(variable=='something'||'something else') posible?

i was wondering in php condition if, if a variable is equal to something or something else like a==b||c or do you need to specify a==b||a==c. sorry newbie here

25th Jun 2017, 4:11 PM
Jake Marvin Villegas
Jake Marvin Villegas - avatar
6 Respostas
+ 2
You'd have to do the second option, because: Variables can hold boolean values (true or false). So, in the first example, a == b || c , we would assume that they are all boolean values, compare b and c, and then see if a is equal to the result. For example: a = true; b = true; c = false; if (a == b || c) # Compare two boolean values with or, and # see if they are the same as the variable a { puts "B or C must evaluate to true!!!" # or print, cout, et cetera }
25th Jun 2017, 4:35 PM
Keto Z
Keto Z - avatar
+ 1
hopelessly php isn't that flexible, you have to do it as you said " a=== b || b=== c", matter fact, no programming language could provide you something like that as far as I have pracisted, you might only do that only if you do your own functions which will implement the way you like, but using the structure of the language of course, so you customize what you have to suit what you need
25th Jun 2017, 4:37 PM
Mohammed Osama El-Morsy
Mohammed Osama El-Morsy - avatar
+ 1
woah took me a while to get it Keto Z, so thats why my code aint working. Thanks for the explanation.
25th Jun 2017, 4:43 PM
Jake Marvin Villegas
Jake Marvin Villegas - avatar
+ 1
typically matching, the number and the data type if you say a= 3 and b ='3' and var_dump each of them you will get that a is integer and b is string, however if you make the condition like that if (a == b) it would match because there is something called type juggling you let the php do the maths and think instead of you however if you do that if ( a=== b) it won't match because it will verify the data type and value, so value is equal but they aren't equal at data type since that's an integer and the other is a string therefore in this condition, it won't be applied
25th Jun 2017, 4:58 PM
Mohammed Osama El-Morsy
Mohammed Osama El-Morsy - avatar
0
Mohammed Osama El-Morsy I think I'll use the second option, i dont know how to write functions yet. Btw what's '===' ?
25th Jun 2017, 4:46 PM
Jake Marvin Villegas
Jake Marvin Villegas - avatar
0
ah! i got it thanks Mohammed, men I need to learn more
25th Jun 2017, 5:39 PM
Jake Marvin Villegas
Jake Marvin Villegas - avatar