var_dump(($value > 0) || (strlen($string) == 2));
||
is a logical logical operatpor, see http://php.net/manual/de/language.operators.logical.php
var_dump(($value > 0) | (strlen($string) == 2));
|
is a bitwise operator, see http://php.net/manual/de/language.operators.bitwise.php
Sure, you can change |
to ||
, but you won't get the same result ;) A little explanation for your code, but you should really read the doc for bit- and logical operators:
You already answered, that both don't do the same:
var_dump(($value < 0) || (strlen($string) == 2));
-> returns a boolean true
var_dump(($value < 0) | (strlen($string) == 2));
-> returns an integer 1
If you do:
var_dump(true === 1);
You will get false, because integer 1 isn't a boolean true, even if:
var_dump(true == 1);
or
var_dump(true === (bool)1);
will return true (==
doesn't check for type, see the docs, and (bool) casts the integer 1 to be a boolean true (see http://php.net/manual/de/language.types.boolean.php#language.types.boolean.casting to know what is false and what is true).