False positives w/ switch
Posted: Fri Aug 11, 2006 2:51 pm
Weirdan | Please use
This is my code. When ever I try 0, 1, or 2 it works. Printing out the correct number, and if I use a number that's not in there(since I have no default set.) It echos nothing. My problem is that when I try something like "cat" it always activates case 0.
I read a little about this, and tried switch(true) and case $i === 0, which is suposed to check for that type only. That didn't work. Why is this so hard? I even tried it with a few if statements. They ALSO saw cat as 0. What's going on here? How did such a simple concept as comparison in other languages become such a challenge in PHP to understand?
Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Sorry about the subject, I don't know how else to describe it.Code: Select all
<?php
$filename = "5";
$i = $_GET['id'];
switch ($i) {
case 0:
$filename = "server0.php";
break;
case 1:
$filename = "server1.php";
break;
case 2:
$filename = "server2.php";
break;
}
echo $filename;
?>I read a little about this, and tried switch(true) and case $i === 0, which is suposed to check for that type only. That didn't work. Why is this so hard? I even tried it with a few if statements. They ALSO saw cat as 0. What's going on here? How did such a simple concept as comparison in other languages become such a challenge in PHP to understand?
Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]