Inline if statements [duplicate] - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Thursday, June 10, 2021

Inline if statements [duplicate]

I have a line of code that looks like:

$var = isset($var) ? $var : 4;

basically I am trying to check if a variable is set (even if its set to empty) and if it isn't , set it to 4

Someone mentioned that I should do it this way:

$var = $var ?? 4;

What I am not sure of (and I am having a hard time search for) is to understand what that is actually doing?

Is the ?? short for asset? is that differentiating between a variable that is set and a variable that is empty?



source https://stackoverflow.com/questions/67909563/inline-if-statements

No comments:

Post a Comment