ainoy31 Posted August 28, 2007 Share Posted August 28, 2007 Hello- I have an issue with returning data to my calling function. Please let me know if I am overseeing something dumb. Code: function x { $this->Mileage($start, $end); $display = sprintf("%0.2f",$miles).' miles'; echo "The total driving distance is: " . $display; } function Mileage($start, $end) { echo "<Starting Coordinates> \n"; echo "Latitude: ". $start[0]['lat'] . " Longitude: ". $start[0]['long']; echo "<br>"; echo "<Ending Coordinates> \n"; echo "Latitude: ". $end[0]['lat'] . " Longitude: ". $end[0]['long']; $lat1 = $start[0]['lat']; $long1 = $start[0]['long']; $lat2 = $end[0]['lat']; $long2 = $end[0]['long']; echo "<br>"; // Formula for calculating distances from latitude and longitude. $dist = acos(sin(deg2rad($lat1))* sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($long1 - $long2))); $dist = rad2deg($dist); return ($miles = (float) $dist * 90.90); } Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 You never assign it to anything. It needs to be $miles = $this->Mileage($start, $end); Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 28, 2007 Share Posted August 28, 2007 Just with a quick glance, it looks to me like you're mising a couple of things. Firstly, when you call your Mileage function, you pass in two variables: $start and $end. Unless these are global variables, they are undefined within your function, x. Second, if you're function returns a value, you need to do something with the returned value, its no use just making a call to the function. Generally, you would either assign the returned value to a variable, or echo the returned value. Edit: Beaten to it, but thought id post anyway, what with the additional information. Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted August 28, 2007 Author Share Posted August 28, 2007 thank you guys. two or more heads are better than one. my variables $start and $end are from a post form. Quote Link to comment 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.