As discussed in the question Data concatenation or sequencing: which one performs best? , this type of concern with language performance does not make much sense. It is known that PHP was not created to be a performatic language, so micro-optimizations in the code will not change the result and should be avoided when doing so the readability and semantics are impaired. Always prefer code that is easier to read than the one that is supposed to be faster.
You ask if there is a performance difference between the two codes, there are none unless you run it a thousand times and then start to see some difference. The resource consumption of the two solutions is the same. Even though in the second there is a variable and in the first one no PHP will need to store the function return in memory anyway, the difference is that with the variable the value will be accessible to the developer (directly).
Even though there is no performance difference, you ask which one is the best. In my opinion, neither is both, because both are difficult to read and are unclear as to the purpose. By reading the documentation, you can see that the parameter N
of date
will return a number for the day of the week of a certain date: 1 for Monday, 7 for Sunday. If you are checking for 3, you need to know if a date is a Wednesday. Neither way makes that clear.
The way I would do it:
$isWednesday = (date('N', strtotime($data)) === "3");
if ($isWednesday) {
...
}
In this way, I do not need to use the documentation of the date
function to know what the code is doing, because the variable name tells me that I am checking for Wednesday.