Thread: case statement
View Single Post
  #10 (permalink)  
Old August 19th, 2003, 01:39 PM
richard.york's Avatar
richard.york richard.york is offline
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

So in writing the if statement equivelent would

if(($foo) == ("A" || "B"))
{
   BLOCK_A;
}

..be the better way?
Or would a more explicit approach be best suited...

if ($foo == "A" || $foo == "B") {

     BLOCK_A;

}

Is what you have written there the exact equivalent?
Actually I might as well just write my own test here...

Code:
<?php

$foo = "D";

if(($foo) == ("A" || "B")) {

    echo "To be!<br />";

} else {

    echo "Or not to be!";

}

if ($foo == "A" || $foo == "B") {

    echo "To be!<br />";

} else {

    echo "Or not to be!<br />";

}

?>
So apparently the first statement is not equivalent with the second as what you mentioned before with the conversion to boolean values is happening!
And the output was:

To be!
Or not to be!

... is there a shortcut???

In terms of the '===' operator, this is best suited for case sensitive or type data comparison, right? I think what I am getting from the manual page that this is for the explicit type comparision of data... well I'll answer my own question again with this little test...

Code:
<?php

$a = 1;
$b = "1";

if ($a === $b) {

    echo "it's true<br />";

} else {

    echo "Not so!<br />";

}

$a = "a";
$b = "A";

if ($a === $b) {

    echo "it's true<br />";

} else {

    echo "Not so!<br />";

}

?>
Since each example evaluates to false I think I'm on the right track here.

: )
Rich



:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
Reply With Quote