babskool Posted October 12, 2006 Share Posted October 12, 2006 Hey guys,Below is my code_________________________________________________________________________function country() {global $step3_country1;if($step3_country1 == "1"){ echo"Brazil";}elseif($step3_country1 == "2"){ echo"China";}elseif($step3_country1 == "3"){ echo"Costa Rica";}else{ echo"No Country Selected";}}$country_name = country();___________________________________________________________________________________Now What if i want to display the result inside something like this: $message.="Country $country_name";Please let me know..Thanks,Shawn :) Link to comment https://forums.phpfreaks.com/topic/23778-php-help-simple/ Share on other sites More sharing options...
wildteen88 Posted October 12, 2006 Share Posted October 12, 2006 Rather than using echo in the country function use a variable and retrun the variable:[code]function country(){ global $step3_country1; switch ($step3_country1) { case '1': $c = 'Brazil'; break; case '2': $c = 'China'; break; case '3': $c = 'Costa Rica'; break; case '4': $c = 'India'; break; case '5': $c = 'Ghana'; break; case '6': $c = 'Kenya'; break; case '7': $c = 'Nepal'; break; case '8': $c = 'Peru'; break; case '9': $c = 'South Africa'; break; case '10': $c = 'Tanzania'; break; case '11': $c = 'Thailand'; break; case '12': $c = 'Sri Lanka'; break; case '1': $c = 'Brazil'; break; default: $c = 'No Country Selected'; } return $c;}$country_name = country();?>[/code]The code used is an adaptation of Kens code. Link to comment https://forums.phpfreaks.com/topic/23778-php-help-simple/#findComment-107994 Share on other sites More sharing options...
babskool Posted October 12, 2006 Author Share Posted October 12, 2006 Now What if i want to display the result inside something like this: $message.="Country $country_name";Please let me know..Thanks, Link to comment https://forums.phpfreaks.com/topic/23778-php-help-simple/#findComment-107997 Share on other sites More sharing options...
wildteen88 Posted October 12, 2006 Share Posted October 12, 2006 Yeah the following:[code]$message.="Country $country_name";[/code]Should work fine. Link to comment https://forums.phpfreaks.com/topic/23778-php-help-simple/#findComment-108007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.