|
Posted by Kimmo Laine on 05/25/05 19:41
"Jam Pa" <anonanon@non-anon.org> kirjoitti
viestiss:Xns9661C49A7B60Canonanonnonanonorgjp@213.243.153.2...
> "Kimmo Laine" <eternal.erectionN0.5P@Mgmail.com> wrote in
> news:d727g3$9e$1@phys-news1.kolumbus.fi:
>>
>> & and | are bitwise arithmetic operators while && and || are boolean
>> operators. What this maeans is that & and | handle single bits in and
>> integer, but && and || evaluate the entire integer as true or false.
> [a LOT deleted]
>
> Thank juu Kimmo! Jotain tollaista mun kokeilutkin indikoi! :)
> Salatiedett!
Eip kest...
> So, what should one use when comparing in if clauses or ternary ? : ops
> when evaluating the validity of user input, for instance?
>
> Is this better?
> if ($gee && $whiz) { //do shiz)
>
> or perhaps
> if ($gee AND $whiz) { //do... }
>
Seems to me that in that particular case there is no difference. Reading the
manual I found an example that sort of demonstrates the effect of OR.
$var0 = "";
$var1 = "bunny";
$default = "default";
$target = $var0 || $var1 || $default;
echo $target; //outputs 1
$target = $var0 OR $var1 OR $default;
echo $target; //outputs bunny
Why "bunny"? Seems that using or the operand is assigned into $target, and
if it's true, it halts. It is evaluated like this:
(($target = $var0) || $target = $var1) || $target = $default;
$target = $var0 is false, since $var0 is empty, but $target = $var1 is true
("bunny" is true) so it halts, since "true or something" is always true, it
"won't bother" to check $default.
--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears
eternal.erectionN0@5P4Mgmail.com
[Back to original message]
|