Jump to content

Strtotime issue with foreach


Tonic-_-

Recommended Posts

This kind of has me in lala land as this is very strange...

 

I'm going through a list of dates in such format.

    [earned] => Array
        (
            [0] => 2010-07-14T11:26:09Z
            [1] => 2010-07-31T06:35:14Z
            [2] => 2010-07-14T11:25:55Z
            [3] => 2010-07-31T06:29:43Z
            [4] => 2010-07-31T06:31:47Z
            [5] => 2010-07-14T11:26:17Z
        )

Everything is setup correctly but the first offset of an array comes back blank. Like so.

- 2010-07-14T11:26:09Z

1280558114 - 2010-07-31T06:35:14Z

1279106755 - 2010-07-14T11:25:55Z

1280557783 - 2010-07-31T06:29:43Z

1280557907 - 2010-07-31T06:31:47Z

1279106777 - 2010-07-14T11:26:17Z

 

Now if I manually use strtotime on just  2010-07-14T11:26:09Z I get the value I seek (1279106769)

 

My foreach setup...

 

foreach($trophy['earned'] as $key2=>$value2)
{
echo strtotime($trophy['earned'][$key2]) . " - " . $trophy['earned'][$key2] . "<br />";
}

 

Any ideas?

Link to comment
Share on other sites

I can't post the entire script due to legal concerns but that's pretty much everything in the foreach. I noticed this because I am inserting information into my database.

 

The $trophy variable contains an array like so..

 

Array
(
    [id] => Array
        (
            [0] => 1
            [1] => 4
            [2] => 5
            [3] => 7
            [4] => 9
            [5] => 11
        )

    [earned] => Array
        (
            [0] => 2010-07-14T11:26:09Z
            [1] => 2010-07-31T06:35:14Z
            [2] => 2010-07-14T11:25:55Z
            [3] => 2010-07-31T06:29:43Z
            [4] => 2010-07-31T06:31:47Z
            [5] => 2010-07-14T11:26:17Z
        )

)

 

The id array works fine and inserts the proper data but the strtotime for the Timestamp does not work properly for the first offset of the array, so I came to the conclusion that it has to be with strtotime it's self as the foreach works the way I want for everything but the strtotime in the foreach does not work on the timestamp. I ruled out the possibility of it being a issue with the timestamp its self just by using strtotime on the value.

 

It's really bothering me..

Link to comment
Share on other sites

I'm starting to lean towards that..

I even just did

 

function blahblah($data)

{

return strtotime($data);

}

 

and the first offset still comes back blank :S I'll just poke around..

 

*EDIT*

Seem's to be something with that first offset... Can't figure out what but thanks anyways.

Link to comment
Share on other sites

@Tonic-_-, almost everything that can be done in a web application has been done countless times. Nothing you are doing in one specific portion of your code is so unique that we haven't already seen it dozens of times.

 

If you cannot troubleshoot what your code is doing and you aren't, can't, or won't post the actual portion of your code responsible for producing the symptom, I don't know just what help you were expecting to get from a programming help forum.

 

Short answer: Don't waste the forum's time with coding problems that cannot be answered because the problem is in code that you did not bother to show in your post.

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.