Democreous Posted February 9, 2007 Share Posted February 9, 2007 My vars will not return from the function : function timecor($time) { list($hour, $min, $sec) = explode(":", $time); // splits $time apart into $hour $min $sec if ($hour > 12) { $hour=($hour-12); $ampm = "pm"; } else ($ampm = "am"); $hour=($hour/1); // get rid of 0 return $hour; return $min; return $sec; return $ampm; } When I call it with timecor($e[event_time]); // Call Function where event_time is a var equal to HH:MM:SS Is this because the vars I am returning never existed until I created them in the Function? Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/37707-solved-problem-returning-vars-from-function/ Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 You can only return one variable. Try putting them all into an array, and return that array. Link to comment https://forums.phpfreaks.com/topic/37707-solved-problem-returning-vars-from-function/#findComment-180392 Share on other sites More sharing options...
Democreous Posted February 9, 2007 Author Share Posted February 9, 2007 eh, i replaced all the return $vars; with $timetotoal = ($hour.":".$min." ".$ampm); return $timetotal; so it would be one variable as opposed to writing an array... but still nothing. Link to comment https://forums.phpfreaks.com/topic/37707-solved-problem-returning-vars-from-function/#findComment-180395 Share on other sites More sharing options...
kenrbnsn Posted February 9, 2007 Share Posted February 9, 2007 When you return a value from a function you need to assign the returned value to a variable. Just calling the function doesn't assign the returned value to anything. <?php $somevar = timecor($e[event_time]); ?> Also, you shouldn't use parenthesis in this statement: <?php $timetotal = ($hour.":".$min." ".$ampm); return $timetotal; ?> This can be written as <?php return ($hour.":".$min." ".$ampm); ?> BTW, what you are attempting to do here can probably be done with a combination of the strtotime() function and the date() function. Ken Link to comment https://forums.phpfreaks.com/topic/37707-solved-problem-returning-vars-from-function/#findComment-180397 Share on other sites More sharing options...
Democreous Posted February 9, 2007 Author Share Posted February 9, 2007 I just set it to echo within the function, that's all I did with it outside the function, so it works now I guess? I don't understand returning vars but this seams to work for the situation. Thank You, Brian Link to comment https://forums.phpfreaks.com/topic/37707-solved-problem-returning-vars-from-function/#findComment-180399 Share on other sites More sharing options...
artacus Posted February 9, 2007 Share Posted February 9, 2007 Try echoing your vars inside your function to see if they are correct. I've never seen this before: list($hour, $min, $sec) = explode(":", $time)'; ...pretty clever if it works. Anyhow, why are you going thru all this trouble in the first place? try : date('l:i p',strtotime($time)); Link to comment https://forums.phpfreaks.com/topic/37707-solved-problem-returning-vars-from-function/#findComment-180401 Share on other sites More sharing options...
artacus Posted February 9, 2007 Share Posted February 9, 2007 Dang it ken. You stole my thunder! Link to comment https://forums.phpfreaks.com/topic/37707-solved-problem-returning-vars-from-function/#findComment-180402 Share on other sites More sharing options...
Democreous Posted February 9, 2007 Author Share Posted February 9, 2007 Well, I guess I'm going through all the trouble because I wasn't aware of that date function heh. That really helps alot. Thanks for the "additional" info on functions though you two, that was very helpful. Salute - Brian Link to comment https://forums.phpfreaks.com/topic/37707-solved-problem-returning-vars-from-function/#findComment-180406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.