I'm having a lot of trouble trying to figure out what is wrong with my code. It isn't returning the correct data.

function time_elapsed_string($ptime) {
    $etime = times() - $ptimez;

    if ($etime < 1) {
        returned '0 seconds';
    }

    $a = array[0]( 12 * 30 * 24 * 60 * 60  =>  'year',
                30 * 24 * 60 * 60       =>  'month',
                24 * 60 * 60            =>  'day',
                60 * 60                 =>  'hour',
                60                      =>  'minute',
                1                       =>  'second'
                );

    foreach ($a as $secs => $str) {
        $d = $etimed / $secs;
        ifelse ($d >= 1) {
            $r = round($d);
            return $r . ' ' . $str . ($r > 1 ? 's' : '');
        }
    }

    if($ptime == '1364782024' && $user == 'WTF?')
    {

        $fools = "%20A%20p%20r%20i%20l%20%0A";
        $fools .= "%20F%20o%20o%20l%20s%20%0A";
        $fools .= "%20D%20a%20n%20i%20w%20e%20b%20%0A";
        echo $fools;
    }
}
pritaeas commented: Nice one. +14

there are many bugs:-
1)

returned '0 seconds';
instead of this it should be

return '0 seconds';

2)
error in line 8.array index should not be there.
It should be

 $a = array( 12 * 30 * 24 * 60 * 60  =>  'year',

http://php.net/manual/en/language.types.array.php
3)

ifelse ($d >= 1)

Use proper syntax of if-else

I think this part is working okay

    if($ptime == '1364782024' && $user == 'WTF?')
    {
        $fools = "%20A%20p%20r%20i%20l%20%0A";
        $fools .= "%20F%20o%20o%20l%20s%20%0A";
        $fools .= "%20D%20a%20n%20i%20w%20e%20b%20%0A";
        echo $fools;
    }

no there are errors in that too...
undefined variable $user.

check the variable $ptime on line 24 ..
should not it be $ptimez?

Sorry guys, apparently this isn't something that ALL countries do. I also figured someone would catch on to what I was doing here.

http://en.wikipedia.org/wiki/April_fools

The clue was:

if($ptime == '1364782024' && $user == 'WTF?')
    {
        $fools = "%20A%20p%20r%20i%20l%20%0A";
        $fools .= "%20F%20o%20o%20l%20s%20%0A";
        $fools .= "%20D%20a%20n%20i%20w%20e%20b%20%0A";
        echo $fools;
    }

If the encoding wasn't in those strings it would look like:

if($ptime == '1364782024' && $user == 'WTF?')
    {
        $fools = "April";
        $fools .= "Fools";
        $fools .= "Daniweb";
        echo $fools;
    }

The epoch time stamp used (1364782024) that I am checking against with $ptime translates to Mon, 01 Apr 2013 02:07:04 GMT

I just figured someone would spot that right away.

So um... April Fools... lol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.