Jump to content

learning exercise...


AV1611

Recommended Posts

I don't understand the result this gives:
[code]
<?php
function 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]
428225
428275

total: 0
[/code]
Shouldn't total be like 50 ???
Link to comment
Share on other sites

I have figured it out I think..I am a noobie and decided to try and answer this one from a "lack of knowledge" perspective

the 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 fine

laugh at me all you like, I am new and am trying my best.......

Paul
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.