0

I have the following array:

$Output = Array
    (
        [0] => 2013-08-28 13:04:50-05:00
        [1] => 2013-08-28 18:31:29-05:00
        [2] => 2013-08-30 15:08:23-05:00
        [3] => 2013-08-30 21:45:48-05:00
        [4] => 2013-08-31 16:57:50-05:00
    )

Now i need to convert each element to a string so I can compare it with these variables:

$hr24 = strtotime(date('Y-m-d H:i:sP',strtotime("-1 days")));
$hr72 = strtotime(date('Y-m-d H:i:sP',strtotime("-3 days")));

So what I want to do is, if the array element is over 24hr, write it to a TXT file, and if is over 72hr write to a different one. So i have this:

$OutputStr = serialize($Output);
$OutputStr = strtotime($OutputStr);

if ($OutputStr > $hr24) {
file_put_contents('/folder/test/test24hr_log.txt', print_r($OutputStr, true));
                    }
    elseif ($OutputStr > $hr72) {
        file_put_contents('/folder/test/test72hr_log.txt', print_r($OutputStr, true));
            }

But is not giving me any answer, does anybody have an idea? I dont know if im doing the right comparison for each element. Any help is appreciated thanks!

1
  • var_dump($OutputStr). Then think. Commented Sep 4, 2013 at 18:51

1 Answer 1

1
$hr24 = strtotime("-1 days");
$hr72 = strtotime("-3 days");
$older24 = array();
$older72 = array();
foreach ($Output AS $date) {
  $time = strtotime($date);
  if ($time < $hr72) {
    $older72[] = $date;
  } else if ($time < $hr24) {
    $older24[] = $date;
  }
}
file_put_contents('/folder/test/test24hr_log.txt', serialize($older24));
file_put_contents('/folder/test/test72hr_log.txt', serialize($older72));

http://phpfiddle.org/lite/code/q3r-j5y

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, I tried your answer, but it seems to be writing all the files on the same TXT file. file_put_contents('/folder/test72hr_log.txt', print_r($Output, true));
Thanks, it worked i just have to figure it out how to pass all that data into that TXT, is just taking the last value
For example, create 2 new arrays for storing these strings. Add each string to appropriate array. After the loop store these arrays to files.
Yes that's what i thought to do

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.