Bifter Posted November 10, 2009 Share Posted November 10, 2009 Hi all, I have the following: <?php // Varibles $switch_type = $_GET['st']; $switch_speed = $_GET['ss']; $switch_size = $_GET['ssize']; // Managed or Unmanaged if ($_GET['st'] == "managed"){ $a1 = "answer-left"; } else if ($_GET['st'] == "unmanaged"){ $a1 = "answer-right"; } else if ($_GET['st'] == "smart"){ $a1 = "answer-mid"; } else { echo ""; } //2nd line $a2 = "answer"; // Type of switch switch($_GET['st']) { case "managed": $a2 = $a1 + "-left"; break; case "unmanaged": $a2 = $a1 + "-right"; break; case "smart": $a2 = $a1 + "-mid"; break; } // speed of switch if (isset($_GET['ss'])) { switch($_GET['ss']) { case 100: $a2 = $a2 + "-left"; break; case 1000: $a2 = $a2 + "-right"; break; } } echo $a1. "<br />"; echo $a2. "<br />"; ?> The problem is that $a2 always echo's 0 - am I missing something? Also is there a better way of doing this? Link to comment https://forums.phpfreaks.com/topic/180992-help-with-switch/ Share on other sites More sharing options...
genericnumber1 Posted November 10, 2009 Share Posted November 10, 2009 when you concatenate strings, you do it with '.', not '+'. The plus will attempt to add the two strings and give unpredictable results. Use the concatenation operator Eg. $a2 = $a2 . "-left"; Link to comment https://forums.phpfreaks.com/topic/180992-help-with-switch/#findComment-954912 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.