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