Does anyone know what this piece of code means?

I am following a booking calendar youtube tutorial and they have used this piece of code, but I don’t know what it means or what the rules are for it.

$today = $date == date('Y-m-d')?"today" : "";

They have assigned $date a value and then made that equal $today - which I have never seen before, and then I cannot understand the ? after the date brackets.

Does anyone know what this code is actually saying and if there are references to this somewhere in the php manual?

Hello.

IF <condition> ? THEN <some action> : ELSE <another action>

So IF $date logically equals date(‘Y-m-d’) THEN assign “today” string to $today variable, ELSE assign an empty string “” to $today variable.

HTH. :slight_smile:

2 Likes

Go to the PHP Manual then search for Operators. Read a bit of that. The second paragraph has the answer. While there, have a look at the other operators.

1 Like

Hi, UpsateLeafPeeper and SamuelCalifornia, both your answers are super helpful and have solved my question.

https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary

1 Like