The existing variable $ time may be of the time type and may be a Unix timestamp, that is, $ time & #039; 2011-12-2500: 11: 20 & #039 ;; or $ time1324742400. now I want to make a unified conversion, that is, if it is a time type, convert it to U using the strtotime ($ time) function... the existing variable $ time may be of the time type and may be a Unix timestamp, that is
$time = '2011-12-25 00:11:20';
Or
$time = 1324742400
.
Now I want to make a transformation for unification, that is, if it isTime Type
And use it.strtotime($time)
Converts a function to a Unix timestamp. If this function is not usedstrtotime($time)
Will returnfalse
.
Then I use the question mark expression.$time = strtotime($time) ? strtotime($time) : $time;
Is there a more concise form to meet this requirement? Do you always feel that someone else did not write this?
Reply content:
The existing variable $ time may be of the time type and may be a Unix timestamp, that is$time = '2011-12-25 00:11:20';
Or$time = 1324742400
.
Now I want to make a transformation for unification, that is, if it isTime Type
And use it.strtotime($time)
Converts a function to a Unix timestamp. If this function is not usedstrtotime($time)
Will returnfalse
.
Then I use the question mark expression.$time = strtotime($time) ? strtotime($time) : $time;
Is there a more concise form to meet this requirement? Do you always feel that someone else did not write this?
The main reason for others to write less is probably that if you writetime
If it is in the time format, it will be executed twice.strtotime
Function.
You can use temporary variables to solve this problem.
$temp = strtotime($time);$time = $temp ? $temp : $time;
For PHP 5.3 or above, you can also use
$time = strtotime($time) ?: $time;
I'm not sure about your problem. If it is a string timestamp, the format must beY-m-d H:i:s
Format?
$time = is_numeric($time) ? $time : strtotime($time);
In fact, you do not need to use the Trielement operator.
!is_numberic($time) && $time = strtotime($time);