tcollie Posted January 4, 2007 Share Posted January 4, 2007 Okay, here's what I have going. I've created a file called cities.php. This file stores information about cities that I'm using in a site. Here is what it looks like:[code]if($city == "1"){ $city_name = "New York"; $city_id = "1"; $loc_01 = "Grand Central Station"; $loc_02 = "Central Park"; $loc_03 = "Maxim Lounge"; $loc_04 = "Madison Square Garden"; $loc_05 = "Coney Island"; //Begin City Specific Switch Here //This page New York City locationsswitch ($location) {case 1: $location_name = 'Grand Central Station'; $loc_pro = 1.5; $loc_thug = 1; break;case 2: $location_name = 'Central Park'; $loc_pro = 1; $loc_thug = 1.95; break;case 3: $location_name = 'Maxim Lounge'; $loc_pro = 1.25; $loc_thug = 1; break;case 4: $location_name = 'Madison Square Garden'; $loc_pro = 1; $loc_thug = 1.25; break;case 5: $location_name = 'Coney Island'; $loc_pro = 0.5; $loc_thug = 0.75; break;}} elseif($city == "2"){ $city_name = "Washington DC"; $city_id = "2"; //Begin City Specific Switch Here}else { echo "You Aren't In Any City";}[/code]Now what I'm attempting to do is create a function that retrieves the values from the switch statements within cities.php. So far I have the following function:[code]function city($city,$location) { include('cities.php'); return $loc_pro; return $loc_thug; }[/code]And my function call is like this:[code]city($city,$location);[/code]So if this is all working correctly I should be able to just pass my variables to my function call and run a simple echo statement to give me the 2 variables in the function that I want. But obviously this isn't working or I wouldn't be posting it here. I can get the results I want if I simply edit the cities.php file and include the 2 variables $city and $location and run an echo script at the bottom of the file. I will show the information that I want. Whenever I try and do it the way I have it written, I just get a blank screen.Can somebody give me some direction on how to make this work, or is there another option for getting the same results that I want? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/32784-need-help-with-a-function/ Share on other sites More sharing options...
tcollie Posted January 4, 2007 Author Share Posted January 4, 2007 Oops, forgot something. The information that I want is in the switch statements basically.For example, If $city = 1 and $location = 1 then result I would be looking for is$echo $loc_pro; //Should dispay 1.5$echo $loc_thug; //Should display 1 Quote Link to comment https://forums.phpfreaks.com/topic/32784-need-help-with-a-function/#findComment-152630 Share on other sites More sharing options...
Jessica Posted January 4, 2007 Share Posted January 4, 2007 Try this: [code]function city($city,$location){ include('cities.php'); global $loc_pro, $loc_thug; $city['pro'] = $loc_pro; $city['thug'] = $loc_thug; return $city;}[/code]AFAIK: You can only return once per function, so what you had won't work.You might want to move this info into a database. Quote Link to comment https://forums.phpfreaks.com/topic/32784-need-help-with-a-function/#findComment-152631 Share on other sites More sharing options...
tcollie Posted January 4, 2007 Author Share Posted January 4, 2007 I'm most likely going to have to move it to the database. This would be much simpler, but I'm really just trying to cut down on calls to the database. Any way, after trying your suggestion, I get the following error:[code]Warning: Cannot use a scalar value as an array in C:\Program Files\xampp\htdocs\thugs\functions.php on line 65Warning: Cannot use a scalar value as an array in C:\Program Files\xampp\htdocs\thugs\functions.php on line 66[/code]I have no clue what "scalar values" are. :o Quote Link to comment https://forums.phpfreaks.com/topic/32784-need-help-with-a-function/#findComment-152636 Share on other sites More sharing options...
Jessica Posted January 4, 2007 Share Posted January 4, 2007 Probably has to do with my reusing the city variable.Try this:[code]function city($city,$location){ include('cities.php'); global $loc_pro, $loc_thug; $info['pro'] = $loc_pro; $info['thug'] = $loc_thug; return $info;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32784-need-help-with-a-function/#findComment-152648 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.