我對邏輯運算符& &和||,或。的使用(以及返回值)我有些懷疑。在比較條件時使用邏輯運算符AND OR
$number = 5;
$numberA = 5;
$numberB = 1;
$string = "x";
$stringA = "x";
$stringB = "y";
If two numbers are compared:
$x=5;
if ($x == $number) { print '$x == $number', "\n"; }
If two strings are compared:
$x="x";
if ($x eq $string) { print '$x eq $string', "\n"; }
但我不知道什麼是評價兩個數字/字符串爲數字/字符串的最佳方式。它是否正確?
$x=5; $y=5;
if (($x && $y) == $number) { print '($x && $y) == $number', "\n"; }
$x="x"; $y="x";
if (($x and $y) eq $string) { print '($x and $y) eq $string', "\n"; }
當兩個邏輯在相同條件下評估時,規則是什麼?應該將條件本身作爲數字進行比較(& &,||)或字符串(和或)?
$x=5; $y=1;
if (($x == $numberA) && ($y == $numberB)) { print '&& or and here?', "\n"; }
$x="x"; $y="y";
if (($x eq $stringA) and ($y eq $stringB)) { print 'and or or here?', "\n"; }
什麼是(5 && 5)給你? – 2014-11-20 23:57:28