note 1926 modified in language.operators.logical by irc-html

From: Date: Sat, 19 Jan 2002 19:15:36 +0000
Subject: note 1926 modified in language.operators.logical by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-25231@lists.php.net to get a copy of this message
[Ed Note: The reason for this is because || has a higher precedence than =, and = has a higher precedence than 'or'. See http://www.php.net/manual/en/language.operators.precedence.php --irc-html@php.net] I wanted to do something like this: $choice1 = ""; $choice2 = "dog"; $default = "other"; $val = $choice1 || $choice2 || $default; but then $val1 will only contain 1 or 0. Instead I did this: $choice1 = ""; $choice2 = "dog"; $default = "other"; $val = $choice1 or $choice2 or $default; now $val contained the string "dog". That's weird that 'or' is different from '||'...and I would think that the '||' should be smart enough to handle strings...the way PERL does. Guess not. Maybe it's a design choice. --was-- I wanted to do something like this: <pre> $choice1 = ""; $choice2 = "dog"; $default = "other"; $val = $choice1 || $choice2 || $default; </pre> but then $val1 will only contain 1 or 0. Instead I did this: <pre> $choice1 = ""; $choice2 = "dog"; $default = "other"; $val = $choice1 or $choice2 or $default; </pre> now $val contained the string "dog". That's weird that 'or' is different from '||'...and I would think that the '||' should be smart enough to handle strings...the way PERL does. Guess not. Maybe it's a design choice. http://www.php.net/manual/en/language.operators.logical.php

« previous php.notes (#25231) next »