AV1611 Posted June 19, 2006 Share Posted June 19, 2006 I don't understand the result this gives:[code]<?phpfunction now(){$row=gettimeofday();echo $row['usec'];}$start=now();echo "<br/><br/>";$stop=now();echo "<br/><br/>";$total=$stop-$start;echo "<br/><br/>";echo "total: ".$total;?>[/code]Here is the result:[code]428225428275total: 0[/code]Shouldn't total be like 50 ??? Quote Link to comment https://forums.phpfreaks.com/topic/12391-learning-exercise/ Share on other sites More sharing options...
kenrbnsn Posted June 19, 2006 Share Posted June 19, 2006 You're not returning a value from the function, you're just echoing it.Try:[code]<?phpfunction now(){ $row=gettimeofday(); return($row['usec']);}?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/12391-learning-exercise/#findComment-47356 Share on other sites More sharing options...
paul2463 Posted June 19, 2006 Share Posted June 19, 2006 I have figured it out I think..I am a noobie and decided to try and answer this one from a "lack of knowledge" perspectivethe function:-function now(){$row=gettimeofday();echo $row['usec'];}does not actually return a value that can be assigned to $start and $stop, all it is asked to do is to write out the value of 'usec'function now(){$row=gettimeofday();echo $row['usec'];return $row['usec'];}makes it work finelaugh at me all you like, I am new and am trying my best.......Paul Quote Link to comment https://forums.phpfreaks.com/topic/12391-learning-exercise/#findComment-47366 Share on other sites More sharing options...
AV1611 Posted June 19, 2006 Author Share Posted June 19, 2006 Hmmm... I think I just found something new to learn about... I've never used "return"Self taught people miss stuff like that sometimes...Thanks, all... Quote Link to comment https://forums.phpfreaks.com/topic/12391-learning-exercise/#findComment-47387 Share on other sites More sharing options...
wildteen88 Posted June 19, 2006 Share Posted June 19, 2006 Surely you would of read something up about return when you learnt how to create functions? Quote Link to comment https://forums.phpfreaks.com/topic/12391-learning-exercise/#findComment-47435 Share on other sites More sharing options...
AV1611 Posted June 20, 2006 Author Share Posted June 20, 2006 as I stated earlier wildteen, this was my very first lesson, but I couldn't get any traction from what php.net had on their site... I had never used "return" before, so didnt' know of it's existance...// I learn out of necessity - I have written many full blown applications that work very good... But, I'm sure if someone with a better PHP education were to look at my code, they would call it very bulky, repetitious and bloated... But, it does work, and it works very well...I am now trying to figure out how to be more EFFICIENT... and someone pointed out to me that I need to learn is how to do functions, as NONE of my programs have them, which would explain why my code is bulky, repetitous, and bloated...I added this to give you context as to what seemed like a dumb question on the outside, but really wasn't dumb at all... Quote Link to comment https://forums.phpfreaks.com/topic/12391-learning-exercise/#findComment-47623 Share on other sites More sharing options...
kenrbnsn Posted June 20, 2006 Share Posted June 20, 2006 Which area in php.net did you look at. The [a href=\"http://www.php.net/manual/en/language.functions.php\" target=\"_blank\"]section on Functions[/a] has a very clearly section on [a href=\"http://www.php.net/manual/en/functions.returning-values.php\" target=\"_blank\"]returning values[/a].Also, if you have programmed in any other language, most have some sort of mechanism for returning values from a called routine back to the calling routine.Ken Quote Link to comment https://forums.phpfreaks.com/topic/12391-learning-exercise/#findComment-47626 Share on other sites More sharing options...
AV1611 Posted June 20, 2006 Author Share Posted June 20, 2006 A. Thanks, I guess I missed it...B. I have no other programming language experience.[!--quoteo(post=385976:date=Jun 20 2006, 07:54 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 20 2006, 07:54 AM) [snapback]385976[/snapback][/div][div class=\'quotemain\'][!--quotec--]Which area in php.net did you look at. The [a href=\"http://www.php.net/manual/en/language.functions.php\" target=\"_blank\"]section on Functions[/a] has a very clearly section on [a href=\"http://www.php.net/manual/en/functions.returning-values.php\" target=\"_blank\"]returning values[/a].Also, if you have programmed in any other language, most have some sort of mechanism for returning values from a called routine back to the calling routine.Ken[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/12391-learning-exercise/#findComment-47642 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.