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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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)); Quote Link to comment Share on other sites More sharing options...
artacus Posted February 9, 2007 Share Posted February 9, 2007 Dang it ken. You stole my thunder! Quote Link to comment 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 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.