Jump to content

[SOLVED] ? and :


sanchez77

Recommended Posts

Take a close look at this statement:

strtotime(sprintf('%s/%s/%s', $m, $d, $y) > time())

 

Evaluating from the inside and out we've got:

A = sprintf('%s/%s/%s', $m, $d, $y) - presumably, this is the some date in the format m/d/y. This is a string.

B = time() - this is the current UNIX timestamp and an integer.

 

So we are evaluating A > B. A will get cast to an integer because we are doing a numeric comparison. The way PHP handles this is by chopping off from the first non-numeric character. So essentially we are checking if the given month is larger than the current UNIX timestamp. This will never be the case, so the operation will return false (a boolean value).

 

Now, a boolean value is an invalid argument to strtotime(), and the way it handles this is by returning false. This means the ternary statement will always return the "false" component, i.e. "#F00" in this case.

 

 

You can of course fix this by fixing the parentheses:

strtotime(sprintf('%s/%s/%s', $m, $d, $y)) > time()

 

I'll let you work out the logic in that statement yourself :)

Link to comment
https://forums.phpfreaks.com/topic/170539-solved-and/#findComment-899565
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.