1

Basically the $usr_timestamp is updated every 10 seconds. Now I have one If statement which states if the $usr_timestamp was updated within the 10 second gap then to echo within the ten seconds What I am trying to achieve is to also echo out not within the ten seconds. I thought that I could achieve this by changing the greater than to a less than however this did not work. Any suggestions?

Example

$usr_timestamp = $usr['timestamp'];
$timeout = time(-10);

if ('$usr_timestamp' > '$timeout'){
echo 'within the ten seconds';
}

What I'm trying to do is set a condition for if the $usr_timestamp hasn't been updated within the last 10 seconds.

This is what I thought would work;

if ($usr_timestamp < '$timeout'){
    echo 'not within the ten seconds.';
}

1 Answers1

0

You are basically checking 2 strings if they are smaller than the other (they would be cast to int and then would both be 0), varables do not get evalutated inside singe quotation marks so you need to use double quotation marks or none of them.

if ($usr_timestamp > $timeout){
   echo 'within the ten seconds';
}
jmattheis
  • 10,494
  • 11
  • 46
  • 58
  • 2
    @LewisDay If you want to read more about what the difference between single and double quotation marks is look [at this question](http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – jmattheis Jun 19 '16 at 15:07