我不完全确定你的意思,但这应该做我认为你想要的:
$time1 = strtotime("first Monday of {$monthname} {$year}");
$time2 = strtotime("third Monday of {$monthname} {$year}");
echo date('jS F Y', time() > $time1 ? $time2 : $time1); // e.g. 1st January 1970
Thetime() > $time1 ? $time2 : $time1
是一个三元条件,基本上意味着
condition ? if_true : if_false
按照您编写的方式,我认为您需要知道可以将变量放在双引号内,例如
$a = 'first';
echo "The $a day of the week"; // echoes 'The first day of the week
但不是单引号,例如
$a = 'first';
echo 'The $a day of the week'; // echoes 'The $a day of the week.
我在变量周围加上了大括号,这样我就可以做到
$a = 'first';
$b = 'variable';
echo "This is the {$a}_{$b}"; // Echoes 'This is the first_variable'
没有大括号
echo "This is the $a_$b" // Undefined variable $a_
或者
try {
// Do something
} catch (Exception $ex) {
echo "There was an error and the message was {$ex->getMessage()}";
}